diff --git a/nixos/modules/services/web-apps/komga.nix b/nixos/modules/services/web-apps/komga.nix index d7ab2a9e612ef..5245552b21305 100644 --- a/nixos/modules/services/web-apps/komga.nix +++ b/nixos/modules/services/web-apps/komga.nix @@ -9,18 +9,31 @@ let cfg = config.services.komga; inherit (lib) mkOption mkEnableOption maintainers; inherit (lib.types) port str bool; + + settingsFormat = pkgs.formats.yaml { }; in { + imports = [ + (lib.mkRenamedOptionModule + [ + "services" + "komga" + "port" + ] + [ + "services" + "komga" + "settings" + "server" + "port" + ] + ) + ]; + options = { services.komga = { enable = mkEnableOption "Komga, a free and open source comics/mangas media server"; - port = mkOption { - type = port; - default = 8080; - description = "The port that Komga will listen on."; - }; - user = mkOption { type = str; default = "komga"; @@ -39,10 +52,25 @@ in description = "State and configuration directory Komga will use."; }; + settings = lib.mkOption { + inherit (settingsFormat) type; + default = { }; + defaultText = lib.literalExpression '' + { + server.port = 8080; + } + ''; + description = '' + Komga configuration. + + See [documentation](https://komga.org/docs/installation/configuration). + ''; + }; + openFirewall = mkOption { type = bool; default = false; - description = "Whether to open the firewall for the port in {option}`services.komga.port`."; + description = "Whether to open the firewall for the port in {option}`services.komga.settings.server.port`."; }; }; }; @@ -52,6 +80,16 @@ in inherit (lib) mkIf getExe; in mkIf cfg.enable { + assertions = [ + { + assertion = (cfg.settings.komga.config-dir or cfg.stateDir) == cfg.stateDir; + message = "You must use the `services.komga.stateDir` option to properly configure `komga.config-dir`."; + } + ]; + + services.komga.settings = { + server.port = lib.mkDefault 8080; + }; networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.port ]; @@ -66,9 +104,17 @@ in }; }; + systemd.tmpfiles.settings."10-komga" = { + ${cfg.stateDir}.d = { + inherit (cfg) user group; + }; + "${cfg.stateDir}/application.yml"."L+" = { + argument = builtins.toString (settingsFormat.generate "application.yml" cfg.settings); + }; + }; + systemd.services.komga = { environment = { - SERVER_PORT = builtins.toString cfg.port; KOMGA_CONFIGDIR = cfg.stateDir; }; diff --git a/nixos/tests/komga.nix b/nixos/tests/komga.nix index d48d19bbbdd37..e5eee346350d0 100644 --- a/nixos/tests/komga.nix +++ b/nixos/tests/komga.nix @@ -8,7 +8,7 @@ import ./make-test-python.nix ({ lib, ... }: { pkgs, ... }: { services.komga = { enable = true; - port = 1234; + settings.server.port = 1234; }; };