2021-02-18 15:02:43 +01:00
|
|
|
{ config, lib, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.my.services.calibre-web;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.my.services.calibre-web = with lib; {
|
|
|
|
enable = mkEnableOption "Calibre-web server";
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8083;
|
|
|
|
example = 8080;
|
|
|
|
description = "Internal port for webui";
|
|
|
|
};
|
|
|
|
|
|
|
|
libraryPath = mkOption {
|
|
|
|
type = with types; either path str;
|
|
|
|
example = /data/media/library;
|
|
|
|
description = "Path to the Calibre library to use";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
2021-04-01 21:22:55 +02:00
|
|
|
services.calibre-web = {
|
|
|
|
enable = true;
|
|
|
|
|
|
|
|
listen = {
|
|
|
|
ip = "127.0.0.1";
|
|
|
|
port = cfg.port;
|
|
|
|
};
|
|
|
|
|
|
|
|
group = "media";
|
|
|
|
|
|
|
|
options = {
|
|
|
|
calibreLibrary = cfg.libraryPath;
|
|
|
|
enableBookConversion = true;
|
2021-02-18 15:02:43 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-09-15 15:57:23 +02:00
|
|
|
# Set-up media group
|
|
|
|
users.groups.media = { };
|
|
|
|
|
2021-08-24 23:05:10 +02:00
|
|
|
my.services.nginx.virtualHosts = [
|
|
|
|
{
|
|
|
|
subdomain = "library";
|
|
|
|
inherit (cfg) port;
|
|
|
|
}
|
|
|
|
];
|
2021-02-18 14:59:47 +01:00
|
|
|
|
|
|
|
my.services.backup = {
|
|
|
|
paths = [
|
2021-11-05 15:54:02 +01:00
|
|
|
"/var/lib/${config.services.calibre-web.dataDir}" # For `app.db` and `gdrive.db`
|
2021-02-18 14:59:47 +01:00
|
|
|
cfg.libraryPath
|
|
|
|
];
|
|
|
|
};
|
2023-02-19 18:36:52 +01:00
|
|
|
|
|
|
|
services.fail2ban.jails = {
|
|
|
|
calibre-web = ''
|
|
|
|
enabled = true
|
|
|
|
filter = calibre-web
|
|
|
|
port = http,https
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc = {
|
|
|
|
"fail2ban/filter.d/calibre-web.conf".text = ''
|
|
|
|
[Definition]
|
|
|
|
failregex = ^.*Login failed for user ".*" IP-address: <HOST>$
|
|
|
|
journalmatch = _SYSTEMD_UNIT=calibre-web.service
|
|
|
|
'';
|
|
|
|
};
|
2021-02-18 15:02:43 +01:00
|
|
|
};
|
|
|
|
}
|