1 { config, lib, pkgs, ... }:
4 cfg = config.services.kavita;
5 settingsFormat = pkgs.formats.json { };
6 appsettings = settingsFormat.generate "appsettings.json" ({ TokenKey = "@TOKEN@"; } // cfg.settings);
10 (lib.mkChangedOptionModule [ "services" "kavita" "ipAdresses" ] [ "services" "kavita" "settings" "IpAddresses" ] (config:
11 let value = lib.getAttrFromPath [ "services" "kavita" "ipAdresses" ] config; in
12 lib.concatStringsSep "," value
14 (lib.mkRenamedOptionModule [ "services" "kavita" "port" ] [ "services" "kavita" "settings" "Port" ])
17 options.services.kavita = {
18 enable = lib.mkEnableOption "Kavita reading server";
23 description = "User account under which Kavita runs.";
26 package = lib.mkPackageOption pkgs "kavita" { };
28 dataDir = lib.mkOption {
29 default = "/var/lib/kavita";
31 description = "The directory where Kavita stores its state.";
34 tokenKeyFile = lib.mkOption {
35 type = lib.types.path;
37 A file containing the TokenKey, a secret with at 512+ bits.
38 It can be generated with `head -c 64 /dev/urandom | base64 --wrap=0`.
42 settings = lib.mkOption {
45 Kavita configuration options, as configured in {file}`appsettings.json`.
47 type = lib.types.submodule {
48 freeformType = settingsFormat.type;
53 type = lib.types.port;
54 description = "Port to bind to.";
57 IpAddresses = lib.mkOption {
58 default = "0.0.0.0,::";
59 type = lib.types.commas;
61 IP Addresses to bind to. The default is to bind to all IPv4 and IPv6 addresses.
69 config = lib.mkIf cfg.enable {
70 systemd.services.kavita = {
71 description = "Kavita";
72 wantedBy = [ "multi-user.target" ];
73 after = [ "network.target" ];
75 install -m600 ${appsettings} ${lib.escapeShellArg cfg.dataDir}/config/appsettings.json
76 ${pkgs.replace-secret}/bin/replace-secret '@TOKEN@' \
77 ''${CREDENTIALS_DIRECTORY}/token \
78 '${cfg.dataDir}/config/appsettings.json'
81 WorkingDirectory = cfg.dataDir;
82 LoadCredential = [ "token:${cfg.tokenKeyFile}" ];
83 ExecStart = lib.getExe cfg.package;
89 systemd.tmpfiles.rules = [
90 "d '${cfg.dataDir}' 0750 ${cfg.user} ${cfg.user} - -"
91 "d '${cfg.dataDir}/config' 0750 ${cfg.user} ${cfg.user} - -"
96 description = "kavita service user";
101 groups.${cfg.user} = { };
105 meta.maintainers = with lib.maintainers; [ misterio77 ];