Skip to content

Commit b71d4f5

Browse files
committed
nixos/pdns-recursor: deprecate settings, add yaml-settings
1 parent 3b3de32 commit b71d4f5

File tree

1 file changed

+102
-33
lines changed

1 file changed

+102
-33
lines changed

nixos/modules/services/networking/pdns-recursor.nix

Lines changed: 102 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,34 @@ let
3838
else
3939
"";
4040

41-
configDir = pkgs.writeTextDir "recursor.conf" (
42-
concatStringsSep "\n" (flip mapAttrsToList cfg.settings (name: val: "${name}=${serialize val}"))
43-
);
41+
settingsFormat = pkgs.formats.yaml { };
4442

4543
mkDefaultAttrs = mapAttrs (n: v: mkDefault v);
4644

45+
mkForwardZone = mapAttrsToList (
46+
zone: uri: {
47+
inherit zone;
48+
forwarders = [ uri ];
49+
}
50+
);
51+
52+
configFile =
53+
if cfg.old-settings != { } then
54+
# Convert recursor.conf to recursor.yml and merge it
55+
let
56+
conf = pkgs.writeText "recursor.conf" (
57+
concatStringsSep "\n" (mapAttrsToList (name: val: "${name}=${serialize val}") cfg.old-settings)
58+
);
59+
60+
yaml = settingsFormat.generate "recursor.yml" cfg.yaml-settings;
61+
in
62+
pkgs.runCommand "recursor-merged.yml" { } ''
63+
${pkgs.pdns-recursor}/bin/rec_control show-yaml --config ${conf} > override.yml
64+
${pkgs.yq-go}/bin/yq '. *= load("override.yml")' ${yaml} > $out
65+
''
66+
else
67+
settingsFormat.generate "recursor.yml" cfg.yaml-settings;
68+
4769
in
4870
{
4971
options.services.pdns-recursor = {
@@ -175,7 +197,7 @@ in
175197
'';
176198
};
177199

178-
settings = mkOption {
200+
old-settings = mkOption {
179201
type = configType;
180202
default = { };
181203
example = literalExpression ''
@@ -184,11 +206,34 @@ in
184206
log-common-errors = true;
185207
}
186208
'';
209+
description = ''
210+
Older PowerDNS Recursor settings. Use this option to configure
211+
Recursor settings not exposed in a NixOS option or to bypass one.
212+
See the full documentation at
213+
<https://doc.powerdns.com/recursor/settings.html>
214+
for the available options.
215+
216+
::: {.warning}
217+
This option is provided for backward compatibility only
218+
and will be removed in the next release of NixOS.
219+
:::
220+
'';
221+
};
222+
223+
yaml-settings = mkOption {
224+
type = settingsFormat.type;
225+
default = { };
226+
example = literalExpression ''
227+
{
228+
loglevel = 8;
229+
log-common-errors = true;
230+
}
231+
'';
187232
description = ''
188233
PowerDNS Recursor settings. Use this option to configure Recursor
189234
settings not exposed in a NixOS option or to bypass one.
190235
See the full documentation at
191-
<https://doc.powerdns.com/recursor/settings.html>
236+
<https://doc.powerdns.com/recursor/yamlsettings.html>
192237
for the available options.
193238
'';
194239
};
@@ -205,42 +250,44 @@ in
205250

206251
config = mkIf cfg.enable {
207252

208-
environment.etc."pdns-recursor".source = configDir;
253+
environment.etc."/pdns-recursor/recursor.yml".source = configFile;
209254

210-
services.pdns-recursor.settings = mkDefaultAttrs {
211-
local-address = cfg.dns.address;
212-
local-port = cfg.dns.port;
213-
allow-from = cfg.dns.allowFrom;
255+
services.pdns-recursor.yaml-settings = {
256+
incoming = mkDefaultAttrs {
257+
listen = cfg.dns.address;
258+
port = cfg.dns.port;
259+
allow_from = cfg.dns.allowFrom;
260+
};
261+
262+
webservice = mkDefaultAttrs {
263+
address = cfg.api.address;
264+
port = cfg.api.port;
265+
allow_from = cfg.api.allowFrom;
266+
};
214267

215-
webserver-address = cfg.api.address;
216-
webserver-port = cfg.api.port;
217-
webserver-allow-from = cfg.api.allowFrom;
268+
recursor = mkDefaultAttrs {
269+
forward_zones = mkForwardZone cfg.forwardZones;
270+
forward_zones_recurse = mkForwardZone cfg.forwardZonesRecurse;
271+
export_etc_hosts = cfg.exportHosts;
272+
serve_rfc1918 = cfg.serveRFC1918;
273+
lua_config_file = pkgs.writeText "recursor.lua" cfg.luaConfig;
274+
daemon = false;
275+
write_pid = false;
276+
};
218277

219-
forward-zones = mapAttrsToList (zone: uri: "${zone}.=${uri}") cfg.forwardZones;
220-
forward-zones-recurse = mapAttrsToList (zone: uri: "${zone}.=${uri}") cfg.forwardZonesRecurse;
221-
export-etc-hosts = cfg.exportHosts;
222-
dnssec = cfg.dnssecValidation;
223-
serve-rfc1918 = cfg.serveRFC1918;
224-
lua-config-file = pkgs.writeText "recursor.lua" cfg.luaConfig;
278+
dnssec = mkDefaultAttrs {
279+
validation = cfg.dnssecValidation;
280+
};
225281

226-
daemon = false;
227-
write-pid = false;
228-
log-timestamp = false;
229-
disable-syslog = true;
282+
logging = mkDefaultAttrs {
283+
timestamp = false;
284+
disable_syslog = true;
285+
};
230286
};
231287

232288
systemd.packages = [ pkgs.pdns-recursor ];
233289

234-
systemd.services.pdns-recursor = {
235-
wantedBy = [ "multi-user.target" ];
236-
237-
serviceConfig = {
238-
ExecStart = [
239-
""
240-
"${pkgs.pdns-recursor}/bin/pdns_recursor --config-dir=${configDir}"
241-
];
242-
};
243-
};
290+
systemd.services.pdns-recursor.wantedBy = [ "multi-user.target" ];
244291

245292
users.users.pdns-recursor = {
246293
isSystemUser = true;
@@ -250,6 +297,15 @@ in
250297

251298
users.groups.pdns-recursor = { };
252299

300+
warnings = lib.optional (cfg.old-settings != { }) ''
301+
pdns-recursor has changed its configuration file format from pdns-recursor.conf
302+
(mapped to `services.pdns-recursor.old-settings`) to the newer pdns-recursor.yml
303+
(mapped to `services.pdns-recursor.yaml-settings`).
304+
305+
Support for the older format will be removed in a future version, so please migrate
306+
your settings over. See <https://doc.powerdns.com/recursor/yamlsettings.html>.
307+
'';
308+
253309
};
254310

255311
imports = [
@@ -258,6 +314,19 @@ in
258314
"pdns-recursor"
259315
"extraConfig"
260316
] "To change extra Recursor settings use services.pdns-recursor.settings instead.")
317+
318+
(mkRenamedOptionModule
319+
[
320+
"services"
321+
"pdns-recursor"
322+
"settings"
323+
]
324+
[
325+
"services"
326+
"pdns-recursor"
327+
"old-settings"
328+
]
329+
)
261330
];
262331

263332
meta.maintainers = with lib.maintainers; [ rnhmjoj ];

0 commit comments

Comments
 (0)