From 68bcdbfc9efe20a27262c7ef79a3a2ab707d1e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Tue, 31 Oct 2023 01:09:57 +0100 Subject: [PATCH] nixos/prosody: substitute environment variables to allow securely loading secrets --- nixos/modules/services/networking/prosody.nix | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/networking/prosody.nix b/nixos/modules/services/networking/prosody.nix index d1de1854c938..4fef467d1d97 100644 --- a/nixos/modules/services/networking/prosody.nix +++ b/nixos/modules/services/networking/prosody.nix @@ -879,7 +879,11 @@ in extraConfig = mkOption { type = types.lines; default = ""; - description = "Additional prosody configuration"; + description = '' + Additional prosody configuration + + The generated file is processed by `envsubst` to allow secrets to be passed securely via environment variables. + ''; }; log = mkOption { @@ -973,13 +977,19 @@ in wants = [ "network-online.target" ]; wantedBy = [ "multi-user.target" ]; restartTriggers = [ config.environment.etc."prosody/prosody.cfg.lua".source ]; + preStart = '' + ${pkgs.envsubst}/bin/envsubst -i ${ + config.environment.etc."prosody/prosody.cfg.lua".source + } -o /run/prosody/prosody.cfg.lua + ''; serviceConfig = mkMerge [ { User = cfg.user; Group = cfg.group; Type = "simple"; - RuntimeDirectory = [ "prosody" ]; + RuntimeDirectory = "prosody"; PIDFile = "/run/prosody/prosody.pid"; + Environment = "PROSODY_CONFIG=/run/prosody/prosody.cfg.lua"; ExecStart = "${lib.getExe cfg.package} -F"; ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; Restart = "on-abnormal";