2022-10-15 15:29:21 +00:00
|
|
|
{ config, pkgs, lib, ... }: {
|
2022-10-01 21:39:36 +00:00
|
|
|
|
2022-10-16 03:47:21 +00:00
|
|
|
imports = [ ./caddy.nix ./backups.nix ];
|
2022-10-02 15:24:25 +00:00
|
|
|
|
2022-10-02 14:48:51 +00:00
|
|
|
options = {
|
|
|
|
bookServer = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "Hostname for Calibre library";
|
|
|
|
};
|
|
|
|
};
|
2022-10-01 21:39:36 +00:00
|
|
|
|
|
|
|
config = {
|
|
|
|
|
|
|
|
services.calibre-web = {
|
|
|
|
enable = true;
|
|
|
|
openFirewall = true;
|
|
|
|
options = {
|
|
|
|
reverseProxyAuth.enable = false;
|
|
|
|
enableBookConversion = true;
|
2022-10-05 03:59:13 +00:00
|
|
|
enableBookUploading = true;
|
2022-10-01 21:39:36 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-10-05 03:59:13 +00:00
|
|
|
# Fix: https://github.com/janeczku/calibre-web/issues/2422
|
|
|
|
nixpkgs.overlays = [
|
|
|
|
(final: prev: {
|
|
|
|
calibre-web = prev.calibre-web.overrideAttrs (old: {
|
|
|
|
patches = (old.patches or [ ]) ++ [ ./calibre-web-cloudflare.patch ];
|
|
|
|
});
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
2022-10-02 17:40:10 +00:00
|
|
|
caddyRoutes = [{
|
|
|
|
match = [{ host = [ config.bookServer ]; }];
|
|
|
|
handle = [{
|
|
|
|
handler = "reverse_proxy";
|
|
|
|
upstreams = [{ dial = "localhost:8083"; }];
|
|
|
|
headers.request.add."X-Script-Name" = [ "/calibre-web" ];
|
2022-10-02 15:24:25 +00:00
|
|
|
}];
|
2022-10-02 17:40:10 +00:00
|
|
|
}];
|
2022-10-02 14:48:51 +00:00
|
|
|
|
2022-10-16 03:47:21 +00:00
|
|
|
# Run a backup on a schedule
|
|
|
|
systemd.timers.calibre-backup = {
|
|
|
|
timerConfig = {
|
|
|
|
OnCalendar = "*-*-* 00:00:00"; # Once per day
|
|
|
|
Unit = "calibre-backup.service";
|
|
|
|
};
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
# Backup Calibre data to object storage
|
|
|
|
systemd.services.calibre-backup =
|
|
|
|
let libraryPath = "/var/lib/calibre-web"; # Default location
|
|
|
|
in {
|
|
|
|
description = "Backup Calibre data";
|
|
|
|
environment.AWS_ACCESS_KEY_ID = config.backupS3.accessKeyId;
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
User = "calibre-web";
|
|
|
|
Group = "backup";
|
|
|
|
EnvironmentFile = config.secrets.backup.dest;
|
|
|
|
};
|
|
|
|
script = ''
|
|
|
|
${pkgs.awscli2}/bin/aws s3 sync \
|
|
|
|
${libraryPath}/ \
|
|
|
|
s3://${config.backupS3.bucket}/calibre/ \
|
|
|
|
--endpoint-url=https://${config.backupS3.endpoint}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-10-01 21:39:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|