|
38 | 38 | else |
39 | 39 | ""; |
40 | 40 |
|
41 | | - configDir = pkgs.writeTextDir "recursor.conf" ( |
42 | | - concatStringsSep "\n" (flip mapAttrsToList cfg.settings (name: val: "${name}=${serialize val}")) |
43 | | - ); |
| 41 | + settingsFormat = pkgs.formats.yaml { }; |
44 | 42 |
|
45 | 43 | mkDefaultAttrs = mapAttrs (n: v: mkDefault v); |
46 | 44 |
|
| 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 | + |
47 | 69 | in |
48 | 70 | { |
49 | 71 | options.services.pdns-recursor = { |
|
175 | 197 | ''; |
176 | 198 | }; |
177 | 199 |
|
178 | | - settings = mkOption { |
| 200 | + old-settings = mkOption { |
179 | 201 | type = configType; |
180 | 202 | default = { }; |
181 | 203 | example = literalExpression '' |
|
184 | 206 | log-common-errors = true; |
185 | 207 | } |
186 | 208 | ''; |
| 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 | + ''; |
187 | 232 | description = '' |
188 | 233 | PowerDNS Recursor settings. Use this option to configure Recursor |
189 | 234 | settings not exposed in a NixOS option or to bypass one. |
190 | 235 | See the full documentation at |
191 | | - <https://doc.powerdns.com/recursor/settings.html> |
| 236 | + <https://doc.powerdns.com/recursor/yamlsettings.html> |
192 | 237 | for the available options. |
193 | 238 | ''; |
194 | 239 | }; |
|
205 | 250 |
|
206 | 251 | config = mkIf cfg.enable { |
207 | 252 |
|
208 | | - environment.etc."pdns-recursor".source = configDir; |
| 253 | + environment.etc."/pdns-recursor/recursor.yml".source = configFile; |
209 | 254 |
|
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 | + }; |
214 | 267 |
|
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 | + }; |
218 | 277 |
|
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 | + }; |
225 | 281 |
|
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 | + }; |
230 | 286 | }; |
231 | 287 |
|
232 | 288 | systemd.packages = [ pkgs.pdns-recursor ]; |
233 | 289 |
|
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" ]; |
244 | 291 |
|
245 | 292 | users.users.pdns-recursor = { |
246 | 293 | isSystemUser = true; |
|
250 | 297 |
|
251 | 298 | users.groups.pdns-recursor = { }; |
252 | 299 |
|
| 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 | + |
253 | 309 | }; |
254 | 310 |
|
255 | 311 | imports = [ |
|
258 | 314 | "pdns-recursor" |
259 | 315 | "extraConfig" |
260 | 316 | ] "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 | + ) |
261 | 330 | ]; |
262 | 331 |
|
263 | 332 | meta.maintainers = with lib.maintainers; [ rnhmjoj ]; |
|
0 commit comments