From d54d70f16615992b8005e7bec4b0d77954a95346 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Wed, 13 Jul 2022 19:03:50 +0200 Subject: [PATCH 1/2] nixos/mxisd: allow passing secrets Suppose you want to provide a LDAP-based directory search to your homeserver via a service-user with a bind-password. To make sure that this doesn't end up in the Nix store, it's now possible to set a substitute for the bindPassword like services.mxisd.extraConfig.ldap.connection = { # host, bindDn etc. bindPassword = "$LDAP_BIND_PW"; }; and write the actual secret into an environment file that's readable for `mxisd.service` containing LDAP_BIND_PW= and the following setting in the Nix expression: services.mxisd.environmentFile = "/runs/ecrets/mxisd"; (cherry picked from commit aa25ce7aa1a89618e4257fd46c7d20879f54c728) --- nixos/modules/services/networking/mxisd.nix | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/networking/mxisd.nix b/nixos/modules/services/networking/mxisd.nix index 803f0689d1fd..267c605040ea 100644 --- a/nixos/modules/services/networking/mxisd.nix +++ b/nixos/modules/services/networking/mxisd.nix @@ -46,6 +46,15 @@ in { description = "The mxisd/ma1sd package to use"; }; + environmentFile = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + Path to an environment-file which may contain secrets to be + substituted via envsubst. + ''; + }; + dataDir = mkOption { type = types.str; default = "/var/lib/mxisd"; @@ -118,7 +127,12 @@ in { Type = "simple"; User = "mxisd"; Group = "mxisd"; - ExecStart = "${cfg.package}/bin/${executable} -c ${configFile}"; + EnvironmentFile = mkIf (cfg.environmentFile != null) cfg.environmentFile; + ExecStart = "${cfg.package}/bin/${executable} -c ${cfg.dataDir}/mxisd-config.yaml"; + ExecStartPre = "${pkgs.writeShellScript "mxisd-substitute-secrets" '' + ${pkgs.envsubst}/bin/envsubst -o ${cfg.dataDir}/mxisd-config.yaml \ + -i ${configFile} + ''}"; WorkingDirectory = cfg.dataDir; Restart = "on-failure"; }; From c2c82fbe43c6f793b3e4999eaa5775b5f1c07508 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Mon, 18 Jul 2022 13:47:09 +0200 Subject: [PATCH 2/2] nixos/mxisd: use a list for env file for mergeability --- nixos/modules/services/networking/mxisd.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/services/networking/mxisd.nix b/nixos/modules/services/networking/mxisd.nix index 267c605040ea..5b1e0dee8e35 100644 --- a/nixos/modules/services/networking/mxisd.nix +++ b/nixos/modules/services/networking/mxisd.nix @@ -127,7 +127,7 @@ in { Type = "simple"; User = "mxisd"; Group = "mxisd"; - EnvironmentFile = mkIf (cfg.environmentFile != null) cfg.environmentFile; + EnvironmentFile = mkIf (cfg.environmentFile != null) [ cfg.environmentFile ]; ExecStart = "${cfg.package}/bin/${executable} -c ${cfg.dataDir}/mxisd-config.yaml"; ExecStartPre = "${pkgs.writeShellScript "mxisd-substitute-secrets" '' ${pkgs.envsubst}/bin/envsubst -o ${cfg.dataDir}/mxisd-config.yaml \