2016-09-17 23:30:27 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.powerdns;
|
|
|
|
configDir = pkgs.writeTextDir "pdns.conf" "${cfg.extraConfig}";
|
2022-12-26 02:01:03 +01:00
|
|
|
finalConfigDir = if cfg.secretFile == null then configDir else "/run/pdns";
|
2016-09-17 23:30:27 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.powerdns = {
|
2020-10-14 20:25:38 -04:00
|
|
|
enable = mkEnableOption "PowerDNS domain name server";
|
2016-09-17 23:30:27 +02:00
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "launch=bind";
|
|
|
|
description = ''
|
2020-10-14 20:25:38 -04:00
|
|
|
PowerDNS configuration. Refer to
|
|
|
|
<https://doc.powerdns.com/authoritative/settings.html>
|
|
|
|
for details on supported values.
|
2016-09-17 23:30:27 +02:00
|
|
|
'';
|
|
|
|
};
|
2022-12-26 02:01:03 +01:00
|
|
|
|
|
|
|
secretFile = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
|
|
|
example = "/run/keys/powerdns.env";
|
|
|
|
description = ''
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
2016-09-17 23:30:27 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-10-14 20:25:38 -04:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2023-06-29 12:42:01 +02:00
|
|
|
environment.etc.pdns.source = finalConfigDir;
|
2023-02-25 16:33:36 +01:00
|
|
|
|
2022-03-28 17:48:40 +02:00
|
|
|
systemd.packages = [ pkgs.pdns ];
|
2020-10-14 20:25:38 -04:00
|
|
|
|
2016-09-17 23:30:27 +02:00
|
|
|
systemd.services.pdns = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2020-10-14 20:25:38 -04:00
|
|
|
after = [
|
|
|
|
"network.target"
|
|
|
|
"mysql.service"
|
|
|
|
"postgresql.service"
|
|
|
|
"openldap.service"
|
|
|
|
];
|
2016-09-17 23:30:27 +02:00
|
|
|
|
|
|
|
serviceConfig = {
|
2022-12-26 02:01:03 +01:00
|
|
|
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"
|
|
|
|
];
|
2016-09-17 23:30:27 +02:00
|
|
|
};
|
|
|
|
};
|
2020-10-14 20:25:38 -04:00
|
|
|
|
|
|
|
users.users.pdns = {
|
|
|
|
isSystemUser = true;
|
|
|
|
group = "pdns";
|
|
|
|
description = "PowerDNS";
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.pdns = { };
|
|
|
|
|
2016-09-17 23:30:27 +02:00
|
|
|
};
|
|
|
|
}
|