dotfiles/modules/services/calibre.nix

67 lines
1.7 KiB
Nix
Raw Normal View History

2022-10-01 21:39:36 +00:00
{ config, pkgs, lib, ... }:
let
2022-10-02 14:48:51 +00:00
# Must set group owner to calibre-web
libraryPath = "/var/books";
2022-10-01 21:39:36 +00:00
in {
2022-10-02 15:24:25 +00:00
imports = [ ./caddy.nix ];
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 = {
2022-10-02 14:48:51 +00:00
calibreLibrary = libraryPath;
2022-10-01 21:39:36 +00:00
reverseProxyAuth.enable = false;
enableBookConversion = true;
enableBookUploading = true;
2022-10-01 21:39:36 +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 ];
});
})
];
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 14:48:51 +00:00
# Create directory and set permissions
system.activationScripts.calibreLibrary.text = ''
if [ ! -d "${libraryPath}" ]; then
$DRY_RUN_CMD mkdir --parents $VERBOSE_ARG ${libraryPath}
fi
if [ ! "$(stat -c "%G" ${libraryPath})" = "calibre-web" ]; then
$DRY_RUN_CMD chown $VERBOSE_ARG -R calibre-web:calibre-web ${libraryPath}
fi
if [ ! "$(stat -c "%a" ${libraryPath})" = "775" ]; then
$DRY_RUN_CMD chmod $VERBOSE_ARG 0775 ${libraryPath}
$DRY_RUN_CMD chmod $VERBOSE_ARG -R 0640 ${libraryPath}/*
fi
'';
2022-10-01 21:39:36 +00:00
};
}