diff --git a/nixos/modules/services/web-apps/gotify-server.nix b/nixos/modules/services/web-apps/gotify-server.nix index b700fd14ee52..5f5a9f9f86bb 100644 --- a/nixos/modules/services/web-apps/gotify-server.nix +++ b/nixos/modules/services/web-apps/gotify-server.nix @@ -1,49 +1,90 @@ -{ pkgs, lib, config, ... }: - -with lib; +{ + pkgs, + lib, + config, + ... +}: let cfg = config.services.gotify; -in { - options = { - services.gotify = { - enable = mkEnableOption "Gotify webserver"; +in +{ + imports = [ + (lib.mkRenamedOptionModule + [ + "services" + "gotify" + "port" + ] + [ + "services" + "gotify" + "environment" + "GOTIFY_SERVER_PORT" + ] + ) + ]; - port = mkOption { - type = types.port; - description = '' - Port the server listens to. - ''; - }; + options.services.gotify = { + enable = lib.mkEnableOption "Gotify webserver"; - stateDirectoryName = mkOption { - type = types.str; - default = "gotify-server"; - description = '' - The name of the directory below {file}`/var/lib` where - gotify stores its runtime data. - ''; + package = lib.mkPackageOption pkgs "gotify-server" { }; + + environment = lib.mkOption { + type = lib.types.attrsOf ( + lib.types.oneOf [ + lib.types.str + lib.types.int + ] + ); + default = { }; + example = { + GOTIFY_SERVER_PORT = 8080; + GOTIFY_DATABASE_DIALECT = "sqlite3"; }; + description = '' + Config environment variables for the gotify-server. + See https://gotify.net/docs/config for more details. + ''; + }; + + environmentFiles = lib.mkOption { + type = lib.types.listOf lib.types.path; + default = [ ]; + description = '' + Files containing additional config environment variables for gotify-server. + Secrets should be set in environmentFiles instead of environment. + ''; + }; + + stateDirectoryName = lib.mkOption { + type = lib.types.str; + default = "gotify-server"; + description = '' + The name of the directory below {file}`/var/lib` where + gotify stores its runtime data. + ''; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { systemd.services.gotify-server = { wantedBy = [ "multi-user.target" ]; after = [ "network.target" ]; description = "Simple server for sending and receiving messages"; - environment = { - GOTIFY_SERVER_PORT = toString cfg.port; - }; + environment = lib.mapAttrs (_: toString) cfg.environment; serviceConfig = { WorkingDirectory = "/var/lib/${cfg.stateDirectoryName}"; StateDirectory = cfg.stateDirectoryName; + EnvironmentFile = cfg.environmentFiles; Restart = "always"; - DynamicUser = "yes"; - ExecStart = "${pkgs.gotify-server}/bin/server"; + DynamicUser = true; + ExecStart = lib.getExe cfg.package; }; }; }; + + meta.maintainers = with lib.maintainers; [ DCsunset ]; } diff --git a/nixos/tests/gotify-server.nix b/nixos/tests/gotify-server.nix index c8d7fa172a7b..495b1c8e3443 100644 --- a/nixos/tests/gotify-server.nix +++ b/nixos/tests/gotify-server.nix @@ -9,7 +9,9 @@ import ./make-test-python.nix ({ pkgs, lib, ...} : { services.gotify = { enable = true; - port = 3000; + environment = { + GOTIFY_SERVER_PORT = 3000; + }; }; };