dotfiles/modules/services/calibre.nix

57 lines
1.3 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;
};
};
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
};
}