From 0c2918fc912c25bce8896e70bd2905052d214b47 Mon Sep 17 00:00:00 2001 From: DCsunset Date: Tue, 30 Jul 2024 17:38:00 -0400 Subject: [PATCH] nixos/gotify-server: add environment and environmentFiles options --- .../services/web-apps/gotify-server.nix | 47 ++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/nixos/modules/services/web-apps/gotify-server.nix b/nixos/modules/services/web-apps/gotify-server.nix index a310ced5325a..5f5a9f9f86bb 100644 --- a/nixos/modules/services/web-apps/gotify-server.nix +++ b/nixos/modules/services/web-apps/gotify-server.nix @@ -9,15 +9,51 @@ let cfg = config.services.gotify; in { + imports = [ + (lib.mkRenamedOptionModule + [ + "services" + "gotify" + "port" + ] + [ + "services" + "gotify" + "environment" + "GOTIFY_SERVER_PORT" + ] + ) + ]; + options.services.gotify = { enable = lib.mkEnableOption "Gotify webserver"; package = lib.mkPackageOption pkgs "gotify-server" { }; - port = lib.mkOption { - type = lib.types.port; + 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 = '' - Port the server listens to. + 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. ''; }; @@ -37,13 +73,12 @@ in 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 = true; ExecStart = lib.getExe cfg.package;