nixos/powerdns: add secretFile option
This commit is contained in:
@@ -5,6 +5,7 @@ with lib;
|
|||||||
let
|
let
|
||||||
cfg = config.services.powerdns;
|
cfg = config.services.powerdns;
|
||||||
configDir = pkgs.writeTextDir "pdns.conf" "${cfg.extraConfig}";
|
configDir = pkgs.writeTextDir "pdns.conf" "${cfg.extraConfig}";
|
||||||
|
finalConfigDir = if cfg.secretFile == null then configDir else "/run/pdns";
|
||||||
in {
|
in {
|
||||||
options = {
|
options = {
|
||||||
services.powerdns = {
|
services.powerdns = {
|
||||||
@@ -19,6 +20,19 @@ in {
|
|||||||
for details on supported values.
|
for details on supported values.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
secretFile = mkOption {
|
||||||
|
type = types.nullOr types.path;
|
||||||
|
default = null;
|
||||||
|
example = "/run/keys/powerdns.env";
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
Environment variables from this file will be interpolated into the
|
||||||
|
final config file using envsubst with this syntax: `$ENVIRONMENT`
|
||||||
|
or `''${VARIABLE}`.
|
||||||
|
The file should contain lines formatted as `SECRET_VAR=SECRET_VALUE`.
|
||||||
|
This is useful to avoid putting secrets into the nix store.
|
||||||
|
'';
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -31,7 +45,13 @@ in {
|
|||||||
after = [ "network.target" "mysql.service" "postgresql.service" "openldap.service" ];
|
after = [ "network.target" "mysql.service" "postgresql.service" "openldap.service" ];
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart = [ "" "${pkgs.pdns}/bin/pdns_server --config-dir=${configDir} --guardian=no --daemon=no --disable-syslog --log-timestamp=no --write-pid=no" ];
|
EnvironmentFile = lib.optional (cfg.secretFile != null) cfg.secretFile;
|
||||||
|
ExecStartPre = lib.optional (cfg.secretFile != null)
|
||||||
|
(pkgs.writeShellScript "pdns-pre-start" ''
|
||||||
|
umask 077
|
||||||
|
${pkgs.envsubst}/bin/envsubst -i "${configDir}/pdns.conf" > ${finalConfigDir}/pdns.conf
|
||||||
|
'');
|
||||||
|
ExecStart = [ "" "${pkgs.pdns}/bin/pdns_server --config-dir=${finalConfigDir} --guardian=no --daemon=no --disable-syslog --log-timestamp=no --write-pid=no" ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user