about summary refs log tree commit diff
path: root/nixos/modules/services/web-apps/kavita.nix
diff options
context:
space:
mode:
authorGabriel Fontes <hi@m7.rs>2023-04-30 00:26:37 -0300
committerAnderson Torres <torres.anderson.85@protonmail.com>2023-05-06 13:57:53 -0300
commite2854d332d34310763b60ade9d86bcedfac99e5c (patch)
treeafcce824dac09c8eb44122db79c1abea8207462c /nixos/modules/services/web-apps/kavita.nix
parent76de0ec7503baca369fb7714075eb2dba05c7a93 (diff)
downloadnixlib-e2854d332d34310763b60ade9d86bcedfac99e5c.tar
nixlib-e2854d332d34310763b60ade9d86bcedfac99e5c.tar.gz
nixlib-e2854d332d34310763b60ade9d86bcedfac99e5c.tar.bz2
nixlib-e2854d332d34310763b60ade9d86bcedfac99e5c.tar.lz
nixlib-e2854d332d34310763b60ade9d86bcedfac99e5c.tar.xz
nixlib-e2854d332d34310763b60ade9d86bcedfac99e5c.tar.zst
nixlib-e2854d332d34310763b60ade9d86bcedfac99e5c.zip
nixos/kavita: init
Diffstat (limited to 'nixos/modules/services/web-apps/kavita.nix')
-rw-r--r--nixos/modules/services/web-apps/kavita.nix85
1 files changed, 85 insertions, 0 deletions
diff --git a/nixos/modules/services/web-apps/kavita.nix b/nixos/modules/services/web-apps/kavita.nix
new file mode 100644
index 000000000000..040737eb3b2d
--- /dev/null
+++ b/nixos/modules/services/web-apps/kavita.nix
@@ -0,0 +1,85 @@
+{ config, lib, pkgs, ... }:
+
+let
+  cfg = config.services.kavita;
+in {
+  options.services.kavita = {
+    enable = lib.mkEnableOption (lib.mdDoc "Kavita reading server");
+
+    user = lib.mkOption {
+      type = lib.types.str;
+      default = "kavita";
+      description = lib.mdDoc "User account under which Kavita runs.";
+    };
+
+    package = lib.mkOption {
+      type = lib.types.package;
+      default = pkgs.kavita;
+      defaultText = "pkgs.kavita";
+      description = lib.mdDoc "Kavita package to use.";
+    };
+
+    dataDir = lib.mkOption {
+      default = "/var/lib/kavita";
+      type = lib.types.str;
+      description = lib.mdDoc "The directory where Kavita stores its state.";
+    };
+
+    tokenKeyFile = lib.mkOption {
+      type = lib.types.path;
+      description = lib.mdDoc ''
+        A file containing the TokenKey, a secret with at 128+ bits.
+        It can be generated with `head -c 32 /dev/urandom | base64`.
+      '';
+    };
+    port = lib.mkOption {
+      default = 5000;
+      type = lib.types.port;
+      description = lib.mdDoc "Port to bind to.";
+    };
+    ipAdresses = lib.mkOption {
+      default = ["0.0.0.0" "::"];
+      type = lib.types.listOf lib.types.str;
+      description = lib.mdDoc "IP Adresses to bind to. The default is to bind to all IPv4
+      and IPv6 addresses.";
+    };
+  };
+
+  config = lib.mkIf cfg.enable {
+    systemd.services.kavita = {
+      description = "Kavita";
+      wantedBy = [ "multi-user.target" ];
+      after = [ "network.target" ];
+      preStart = ''
+        mkdir -p "${cfg.dataDir}/config"
+        cat > "${cfg.dataDir}/config/appsettings.json" <<EOF
+        {
+          "TokenKey": "$(cat ${cfg.tokenKeyFile})",
+          "Port": ${toString cfg.port},
+          "IpAddresses": "${lib.concatStringsSep "," cfg.ipAdresses}"
+        }
+        EOF
+        chmod 640 ${cfg.dataDir}/config/appsettings.json
+      '';
+      serviceConfig = {
+        WorkingDirectory = cfg.dataDir;
+        ExecStart = "${lib.getExe cfg.package}";
+        Restart = "always";
+        User = cfg.user;
+      };
+    };
+
+    users = {
+      users.${cfg.user} = {
+        description = "kavita service user";
+        isSystemUser = true;
+        group = cfg.user;
+        home = cfg.dataDir;
+        createHome = true;
+      };
+      groups.${cfg.user} = { };
+    };
+  };
+
+  meta.maintainers = with lib.maintainers; [ misterio77 ];
+}