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