1 { config, lib, pkgs, ... }:
6 cfg = config.services.powerdns;
7 configDir = pkgs.writeTextDir "pdns.conf" "${cfg.extraConfig}";
8 finalConfigDir = if cfg.secretFile == null then configDir else "/run/pdns";
12 enable = mkEnableOption "PowerDNS domain name server";
14 extraConfig = mkOption {
16 default = "launch=bind";
18 PowerDNS configuration. Refer to
19 <https://doc.powerdns.com/authoritative/settings.html>
20 for details on supported values.
24 secretFile = mkOption {
25 type = types.nullOr types.path;
27 example = "/run/keys/powerdns.env";
29 Environment variables from this file will be interpolated into the
30 final config file using envsubst with this syntax: `$ENVIRONMENT`
32 The file should contain lines formatted as `SECRET_VAR=SECRET_VALUE`.
33 This is useful to avoid putting secrets into the nix store.
39 config = mkIf cfg.enable {
41 environment.etc.pdns.source = finalConfigDir;
43 systemd.packages = [ pkgs.pdns ];
45 systemd.services.pdns = {
46 wantedBy = [ "multi-user.target" ];
47 after = [ "network.target" "mysql.service" "postgresql.service" "openldap.service" ];
50 EnvironmentFile = lib.optional (cfg.secretFile != null) cfg.secretFile;
51 ExecStartPre = lib.optional (cfg.secretFile != null)
52 (pkgs.writeShellScript "pdns-pre-start" ''
54 ${pkgs.envsubst}/bin/envsubst -i "${configDir}/pdns.conf" > ${finalConfigDir}/pdns.conf
56 ExecStart = [ "" "${pkgs.pdns}/bin/pdns_server --config-dir=${finalConfigDir} --guardian=no --daemon=no --disable-syslog --log-timestamp=no --write-pid=no" ];
63 description = "PowerDNS";
66 users.groups.pdns = {};