@@ -7,92 +7,118 @@ let
8 username = "nsd";
8 username = "nsd";
9 stateDir = "/var/lib/nsd";
9 stateDir = "/var/lib/nsd";
10− pidFile = stateDir + "/var/nsd.pid";
10+ pidFile = stateDir + "/var/nsd.pid";
12+ # build nsd with the options needed for the given config
12 nsdPkg = pkgs.nsd.override {
13 nsdPkg = pkgs.nsd.override {
13 bind8Stats = cfg.bind8Stats;
14 bind8Stats = cfg.bind8Stats;
14− ipv6 = cfg.ipv6;
15+ ipv6 = cfg.ipv6;
15− ratelimit = cfg.ratelimit.enable;
16+ ratelimit = cfg.ratelimit.enable;
16 rootServer = cfg.rootServer;
17 rootServer = cfg.rootServer;
17− zoneStats = length (collect (x: (x.zoneStats or null) != null) cfg.zones) > 0;
18+ zoneStats = length (collect (x: (x.zoneStats or null) != null) cfg.zones) > 0;
20− zoneFiles = pkgs.stdenv.mkDerivation {
21+
21− preferLocalBuild = true;
22+ nsdEnv = pkgs.buildEnv {
22 name = "nsd-env";
23 name = "nsd-env";
23− buildCommand = concatStringsSep "\n"
24+
24− [ "mkdir -p $out"
25+ paths = [ configFile ]
25− (concatStrings (mapAttrsToList (zoneName: zoneOptions: ''
26+ ++ mapAttrsToList (name: zone: writeZoneData name zone.data) zoneConfigs;
26− cat > "$out/${zoneName}" <<_EOF_
27+
27− ${zoneOptions.data}
28+ postBuild = ''
28− _EOF_
29+ echo "checking zone files"
29− '') zoneConfigs))
30+ cd $out/zones
32+ for zoneFile in *; do
33+ ${nsdPkg}/sbin/nsd-checkzone "$zoneFile" "$zoneFile" || {
34+ if grep -q \\\\\\$ "$zoneFile"; then
35+ echo zone "$zoneFile" contains escaped dollar signes \\\$
36+ echo Escaping them is not needed any more. Please make shure \
37+ to unescape them where they prefix a variable name
44+ echo "checking configuration file"
45+ ${nsdPkg}/sbin/nsd-checkconf $out/nsd.conf
49+ writeZoneData = name: text: pkgs.writeTextFile {
51+ destination = "/zones/${name}";
55+ # options are ordered alphanumerically by the nixos option name
33− configFile = pkgs.writeText "nsd.conf" ''
56+ configFile = pkgs.writeTextDir "nsd.conf" ''
35− username: ${username}
36 chroot: "${stateDir}"
58 chroot: "${stateDir}"
59+ username: ${username}
38 # The directory for zonefile: files. The daemon chdirs here.
61 # The directory for zonefile: files. The daemon chdirs here.
39 zonesdir: "${stateDir}"
62 zonesdir: "${stateDir}"
41 # the list of dynamically added zones.
64 # the list of dynamically added zones.
42− zonelistfile: "${stateDir}/var/zone.list"
43 database: "${stateDir}/var/nsd.db"
65 database: "${stateDir}/var/nsd.db"
44 pidfile: "${pidFile}"
66 pidfile: "${pidFile}"
45 xfrdfile: "${stateDir}/var/xfrd.state"
67 xfrdfile: "${stateDir}/var/xfrd.state"
46 xfrdir: "${stateDir}/tmp"
68 xfrdir: "${stateDir}/tmp"
69+ zonelistfile: "${stateDir}/var/zone.list"
48 # interfaces
71 # interfaces
49 ${forEach " ip-address: " cfg.interfaces}
72 ${forEach " ip-address: " cfg.interfaces}
51− server-count: ${toString cfg.serverCount}
74+ hide-version: ${yesOrNo cfg.hideVersion}
75+ identity: "${cfg.identity}"
52 ip-transparent: ${yesOrNo cfg.ipTransparent}
76 ip-transparent: ${yesOrNo cfg.ipTransparent}
53 do-ip4: ${yesOrNo cfg.ipv4}
77 do-ip4: ${yesOrNo cfg.ipv4}
78+ ipv4-edns-size: ${toString cfg.ipv4EDNSSize}
54 do-ip6: ${yesOrNo cfg.ipv6}
79 do-ip6: ${yesOrNo cfg.ipv6}
55− port: ${toString cfg.port}
80+ ipv6-edns-size: ${toString cfg.ipv6EDNSSize}
56− verbosity: ${toString cfg.verbosity}
81+ log-time-ascii: ${yesOrNo cfg.logTimeAscii}
57− hide-version: ${yesOrNo cfg.hideVersion}
58− identity: "${cfg.identity}"
59 ${maybeString "nsid: " cfg.nsid}
82 ${maybeString "nsid: " cfg.nsid}
83+ port: ${toString cfg.port}
84+ reuseport: ${yesOrNo cfg.reuseport}
85+ round-robin: ${yesOrNo cfg.roundRobin}
86+ server-count: ${toString cfg.serverCount}
87+ ${if cfg.statistics == null then "" else "statistics: ${toString cfg.statistics}"}
60 tcp-count: ${toString cfg.tcpCount}
88 tcp-count: ${toString cfg.tcpCount}
61 tcp-query-count: ${toString cfg.tcpQueryCount}
89 tcp-query-count: ${toString cfg.tcpQueryCount}
62 tcp-timeout: ${toString cfg.tcpTimeout}
90 tcp-timeout: ${toString cfg.tcpTimeout}
63− ipv4-edns-size: ${toString cfg.ipv4EDNSSize}
91+ verbosity: ${toString cfg.verbosity}
64− ipv6-edns-size: ${toString cfg.ipv6EDNSSize}
92+ ${maybeString "version: " cfg.version}
65− ${if cfg.statistics == null then "" else "statistics: ${toString cfg.statistics}"}
66 xfrd-reload-timeout: ${toString cfg.xfrdReloadTimeout}
93 xfrd-reload-timeout: ${toString cfg.xfrdReloadTimeout}
67 zonefiles-check: ${yesOrNo cfg.zonefilesCheck}
94 zonefiles-check: ${yesOrNo cfg.zonefilesCheck}
69− rrl-size: ${toString cfg.ratelimit.size}
70− rrl-ratelimit: ${toString cfg.ratelimit.ratelimit}
71− rrl-whitelist-ratelimit: ${toString cfg.ratelimit.whitelistRatelimit}
72− ${maybeString "rrl-slip: " cfg.ratelimit.slip}
73 ${maybeString "rrl-ipv4-prefix-length: " cfg.ratelimit.ipv4PrefixLength}
96 ${maybeString "rrl-ipv4-prefix-length: " cfg.ratelimit.ipv4PrefixLength}
74 ${maybeString "rrl-ipv6-prefix-length: " cfg.ratelimit.ipv6PrefixLength}
97 ${maybeString "rrl-ipv6-prefix-length: " cfg.ratelimit.ipv6PrefixLength}
98+ rrl-ratelimit: ${toString cfg.ratelimit.ratelimit}
99+ ${maybeString "rrl-slip: " cfg.ratelimit.slip}
100+ rrl-size: ${toString cfg.ratelimit.size}
101+ rrl-whitelist-ratelimit: ${toString cfg.ratelimit.whitelistRatelimit}
76 ${keyConfigFile}
103 ${keyConfigFile}
78 remote-control:
105 remote-control:
79 control-enable: ${yesOrNo cfg.remoteControl.enable}
106 control-enable: ${yesOrNo cfg.remoteControl.enable}
107+ control-key-file: "${cfg.remoteControl.controlKeyFile}"
108+ control-cert-file: "${cfg.remoteControl.controlCertFile}"
80 ${forEach " control-interface: " cfg.remoteControl.interfaces}
109 ${forEach " control-interface: " cfg.remoteControl.interfaces}
81− control-port: ${toString cfg.port}
110+ control-port: ${toString cfg.remoteControl.port}
82 server-key-file: "${cfg.remoteControl.serverKeyFile}"
111 server-key-file: "${cfg.remoteControl.serverKeyFile}"
83 server-cert-file: "${cfg.remoteControl.serverCertFile}"
112 server-cert-file: "${cfg.remoteControl.serverCertFile}"
84− control-key-file: "${cfg.remoteControl.controlKeyFile}"
85− control-cert-file: "${cfg.remoteControl.controlCertFile}"
87− # zone files reside in "${zoneFiles}" linked to "${stateDir}/zones"
88 ${concatStrings (mapAttrsToList zoneConfigFile zoneConfigs)}
114 ${concatStrings (mapAttrsToList zoneConfigFile zoneConfigs)}
90 ${cfg.extraConfig}
116 ${cfg.extraConfig}
93− yesOrNo = b: if b then "yes" else "no";
119+ yesOrNo = b: if b then "yes" else "no";
94 maybeString = pre: s: if s == null then "" else ''${pre} "${s}"'';
120 maybeString = pre: s: if s == null then "" else ''${pre} "${s}"'';
95− forEach = pre: l: concatMapStrings (x: pre + x + "\n") l;
121+ forEach = pre: l: concatMapStrings (x: pre + x + "\n") l;
98 keyConfigFile = concatStrings (mapAttrsToList (keyName: keyOptions: ''
124 keyConfigFile = concatStrings (mapAttrsToList (keyName: keyOptions: ''
@@ -106,22 +132,23 @@ let
106 secret=$(cat "${keyOptions.keyFile}")
132 secret=$(cat "${keyOptions.keyFile}")
107 dest="${stateDir}/private/${keyName}"
133 dest="${stateDir}/private/${keyName}"
108 echo " secret: \"$secret\"" > "$dest"
134 echo " secret: \"$secret\"" > "$dest"
109− ${pkgs.coreutils}/bin/chown ${username}:${username} "$dest"
135+ chown ${username}:${username} "$dest"
110− ${pkgs.coreutils}/bin/chmod 0400 "$dest"
136+ chmod 0400 "$dest"
111 '') cfg.keys);
137 '') cfg.keys);
140+ # options are ordered alphanumerically by the nixos option name
114 zoneConfigFile = name: zone: ''
141 zoneConfigFile = name: zone: ''
116 name: "${name}"
143 name: "${name}"
117 zonefile: "${stateDir}/zones/${name}"
144 zonefile: "${stateDir}/zones/${name}"
118− ${maybeString "zonestats: " zone.zoneStats}
119 ${maybeString "outgoing-interface: " zone.outgoingInterface}
145 ${maybeString "outgoing-interface: " zone.outgoingInterface}
120 ${forEach " rrl-whitelist: " zone.rrlWhitelist}
146 ${forEach " rrl-whitelist: " zone.rrlWhitelist}
147+ ${maybeString "zonestats: " zone.zoneStats}
149+ allow-axfr-fallback: ${yesOrNo zone.allowAXFRFallback}
122 ${forEach " allow-notify: " zone.allowNotify}
150 ${forEach " allow-notify: " zone.allowNotify}
123 ${forEach " request-xfr: " zone.requestXFR}
151 ${forEach " request-xfr: " zone.requestXFR}
124− allow-axfr-fallback: ${yesOrNo zone.allowAXFRFallback}
126 ${forEach " notify: " zone.notify}
153 ${forEach " notify: " zone.notify}
127 notify-retry: ${toString zone.notifyRetry}
154 notify-retry: ${toString zone.notifyRetry}
@@ -142,7 +169,7 @@ let
144 # fighting infinite recursion
171 # fighting infinite recursion
145− zoneOptions = zoneOptionsRaw // childConfig zoneOptions1 true;
172+ zoneOptions = zoneOptionsRaw // childConfig zoneOptions1 true;
146 zoneOptions1 = zoneOptionsRaw // childConfig zoneOptions2 false;
173 zoneOptions1 = zoneOptionsRaw // childConfig zoneOptions2 false;
147 zoneOptions2 = zoneOptionsRaw // childConfig zoneOptions3 false;
174 zoneOptions2 = zoneOptionsRaw // childConfig zoneOptions3 false;
148 zoneOptions3 = zoneOptionsRaw // childConfig zoneOptions4 false;
175 zoneOptions3 = zoneOptionsRaw // childConfig zoneOptions4 false;
@@ -152,26 +179,25 @@ let
153 childConfig = x: v: { options.children = { type = types.attrsOf x; visible = v; }; };
180 childConfig = x: v: { options.children = { type = types.attrsOf x; visible = v; }; };
182+ # options are ordered alphanumerically
155 zoneOptionsRaw = types.submodule {
183 zoneOptionsRaw = types.submodule {
156 options = {
184 options = {
157− children = mkOption {
185+
186+ allowAXFRFallback = mkOption {
158− default = {};
188+ default = true;
159 description = ''
189 description = ''
160− Children zones inherit all options of their parents. Attributes
190+ If NSD as secondary server should be allowed to AXFR if the primary
161− defined in a child will overwrite the ones of its parent. Only
191+ server does not allow IXFR.
162− leaf zones will be actually served. This way it's possible to
163− define maybe zones which share most attributes without
164− duplicating everything. This mechanism replaces nsd's patterns
165− in a save and functional way.
169 allowNotify = mkOption {
195 allowNotify = mkOption {
170− type = types.listOf types.str;
196+ type = types.listOf types.str;
171− default = [ ];
197+ default = [ ];
172− example = [ "192.0.2.0/24 NOKEY" "10.0.0.1-10.0.0.5 my_tsig_key_name"
198+ example = [ "192.0.2.0/24 NOKEY" "10.0.0.1-10.0.0.5 my_tsig_key_name"
173− "10.0.3.4&255.255.0.0 BLOCKED"
199+ "10.0.3.4&255.255.0.0 BLOCKED"
175 description = ''
201 description = ''
176 Listed primary servers are allowed to notify this secondary server.
202 Listed primary servers are allowed to notify this secondary server.
177 <screen><![CDATA[
203 <screen><![CDATA[
@@ -193,28 +219,32 @@ let
196− requestXFR = mkOption {
222+ children = mkOption {
197− type = types.listOf types.str;
198− default = [];
223+ default = {};
200 description = ''
224 description = ''
201− Format: <code>[AXFR|UDP] <ip-address> <key-name | NOKEY></code>
225+ Children zones inherit all options of their parents. Attributes
226+ defined in a child will overwrite the ones of its parent. Only
227+ leaf zones will be actually served. This way it's possible to
228+ define maybe zones which share most attributes without
229+ duplicating everything. This mechanism replaces nsd's patterns
230+ in a save and functional way.
205− allowAXFRFallback = mkOption {
234+ data = mkOption {
206− type = types.bool;
235+ type = types.str;
207− default = true;
236+ default = "";
208 description = ''
238 description = ''
209− If NSD as secondary server should be allowed to AXFR if the primary
239+ The actual zone data. This is the content of your zone file.
210− server does not allow IXFR.
240+ Use imports or pkgs.lib.readFile if you don't want this data in your config file.
214 notify = mkOption {
244 notify = mkOption {
215− type = types.listOf types.str;
245+ type = types.listOf types.str;
216− default = [];
246+ default = [];
217− example = [ "10.0.0.1@3721 my_key" "::5 NOKEY" ];
247+ example = [ "10.0.0.1@3721 my_key" "::5 NOKEY" ];
218 description = ''
248 description = ''
219 This primary server will notify all given secondary servers about
249 This primary server will notify all given secondary servers about
220 zone changes.
250 zone changes.
@@ -231,38 +261,47 @@ let
233 notifyRetry = mkOption {
263 notifyRetry = mkOption {
234− type = types.int;
264+ type = types.int;
235− default = 5;
265+ default = 5;
236 description = ''
266 description = ''
237 Specifies the number of retries for failed notifies. Set this along with notify.
267 Specifies the number of retries for failed notifies. Set this along with notify.
271+ outgoingInterface = mkOption {
272+ type = types.nullOr types.str;
274+ example = "2000::1@1234";
276+ This address will be used for zone-transfere requests if configured
277+ as a secondary server or notifications in case of a primary server.
278+ Supply either a plain IPv4 or IPv6 address with an optional port
241 provideXFR = mkOption {
283 provideXFR = mkOption {
242− type = types.listOf types.str;
284+ type = types.listOf types.str;
243− default = [];
285+ default = [];
244− example = [ "192.0.2.0/24 NOKEY" "192.0.2.0/24 my_tsig_key_name" ];
286+ example = [ "192.0.2.0/24 NOKEY" "192.0.2.0/24 my_tsig_key_name" ];
245 description = ''
287 description = ''
246 Allow these IPs and TSIG to transfer zones, addr TSIG|NOKEY|BLOCKED
288 Allow these IPs and TSIG to transfer zones, addr TSIG|NOKEY|BLOCKED
247 address range 192.0.2.0/24, 1.2.3.4&255.255.0.0, 3.0.2.20-3.0.2.40
289 address range 192.0.2.0/24, 1.2.3.4&255.255.0.0, 3.0.2.20-3.0.2.40
251− outgoingInterface = mkOption {
293+ requestXFR = mkOption {
252− type = types.nullOr types.str;
294+ type = types.listOf types.str;
253− default = null;
295+ default = [];
254− example = "2000::1@1234";
296+ example = [];
255 description = ''
297 description = ''
256− This address will be used for zone-transfere requests if configured
298+ Format: <code>[AXFR|UDP] <ip-address> <key-name | NOKEY></code>
257− as a secondary server or notifications in case of a primary server.
258− Supply either a plain IPv4 or IPv6 address with an optional port
263 rrlWhitelist = mkOption {
302 rrlWhitelist = mkOption {
264− type = types.listOf types.str;
303+ type = types.listOf types.str;
265− default = [];
304+ default = [];
266 description = ''
305 description = ''
267 Whitelists the given rrl-types.
306 Whitelists the given rrl-types.
268 The RRL classification types are: nxdomain, error, referral, any,
307 The RRL classification types are: nxdomain, error, referral, any,
@@ -270,20 +309,10 @@ let
278− The actual zone data. This is the content of your zone file.
279− Use imports or pkgs.lib.readFile if you don't want this data in your config file.
283 zoneStats = mkOption {
312 zoneStats = mkOption {
284− type = types.nullOr types.str;
313+ type = types.nullOr types.str;
285− default = null;
314+ default = null;
286− example = "%s";
315+ example = "%s";
287 description = ''
316 description = ''
288 When set to something distinct to null NSD is able to collect
317 When set to something distinct to null NSD is able to collect
289 statistics per zone. All statistics of this zone(s) will be added
318 statistics per zone. All statistics of this zone(s) will be added
@@ -292,422 +321,470 @@ let
292 and stats_noreset.
321 and stats_noreset.
300− options = {
330+ # options are ordered alphanumerically
301− services.nsd = {
331+ options.services.nsd = {
303− enable = mkEnableOption "NSD authoritative DNS server";
333+ enable = mkEnableOption "NSD authoritative DNS server";
304− bind8Stats = mkEnableOption "BIND8 like statistics";
306− rootServer = mkOption {
335+ bind8Stats = mkEnableOption "BIND8 like statistics";
310− Wheter if this server will be a root server (a DNS root server, you
311− usually don't want that).
315− interfaces = mkOption {
337+ extraConfig = mkOption {
316− type = types.listOf types.str;
338+ type = types.str;
317− default = [ "127.0.0.0" "::1" ];
339+ default = "";
318− description = ''
340+ description = ''
319− What addresses the server should listen to.
341+ Extra nsd config.
323− serverCount = mkOption {
345+ hideVersion = mkOption {
324− type = types.int;
346+ type = types.bool;
325− default = 1;
347+ default = true;
326− description = ''
348+ description = ''
327− Number of NSD servers to fork. Put the number of CPUs to use here.
349+ Wheter NSD should answer VERSION.BIND and VERSION.SERVER CHAOS class queries.
331− ipTransparent = mkOption {
353+ identity = mkOption {
332− type = types.bool;
354+ type = types.str;
333− default = false;
355+ default = "unidentified server";
334− description = ''
356+ description = ''
335− Allow binding to non local addresses.
357+ Identify the server (CH TXT ID.SERVER entry).
339− ipv4 = mkOption {
361+ interfaces = mkOption {
340− type = types.bool;
362+ type = types.listOf types.str;
341− default = true;
363+ default = [ "127.0.0.0" "::1" ];
342− description = ''
364+ description = ''
343− Wheter to listen on IPv4 connections.
365+ What addresses the server should listen to.
347− ipv6 = mkOption {
369+ ipTransparent = mkOption {
348− type = types.bool;
370+ type = types.bool;
349− default = true;
371+ default = false;
350− description = ''
372+ description = ''
351− Wheter to listen on IPv6 connections.
373+ Allow binding to non local addresses.
355− port = mkOption {
377+ ipv4 = mkOption {
356− type = types.int;
378+ type = types.bool;
357− default = 53;
379+ default = true;
358− description = ''
380+ description = ''
359− Port the service should bind do.
381+ Wheter to listen on IPv4 connections.
385+ ipv4EDNSSize = mkOption {
389+ Preferred EDNS buffer size for IPv4.
397+ Wheter to listen on IPv6 connections.
401+ ipv6EDNSSize = mkOption {
405+ Preferred EDNS buffer size for IPv6.
409+ logTimeAscii = mkOption {
413+ Log time in ascii, if false then in unix epoch seconds.
418+ type = types.nullOr types.str;
421+ NSID identity (hex string, or "ascii_somestring").
429+ Port the service should bind do.
433+ reuseport = mkOption {
435+ default = pkgs.stdenv.isLinux;
437+ Wheter to enable SO_REUSEPORT on all used sockets. This lets multiple
438+ processes bind to the same port. This speeds up operation especially
439+ if the server count is greater than one and makes fast restarts less
444+ rootServer = mkOption {
448+ Wheter if this server will be a root server (a DNS root server, you
449+ usually don't want that).
453+ roundRobin = mkEnableOption "round robin rotation of records";
455+ serverCount = mkOption {
459+ Number of NSD servers to fork. Put the number of CPUs to use here.
463+ statistics = mkOption {
464+ type = types.nullOr types.int;
467+ Statistics are produced every number of seconds. Prints to log.
468+ If null no statistics are logged.
472+ tcpCount = mkOption {
476+ Maximum number of concurrent TCP connections per server.
480+ tcpQueryCount = mkOption {
484+ Maximum number of queries served on a single TCP connection.
489+ tcpTimeout = mkOption {
493+ TCP timeout in seconds.
363− verbosity = mkOption {
497+ verbosity = mkOption {
364− type = types.int;
498+ type = types.int;
365− default = 0;
499+ default = 0;
366− description = ''
500+ description = ''
367− Verbosity level.
501+ Verbosity level.
505+ version = mkOption {
506+ type = types.nullOr types.str;
509+ The version string replied for CH TXT version.server and version.bind
510+ queries. Will use the compiled package version on null.
511+ See hideVersion for enabling/disabling this responses.
515+ xfrdReloadTimeout = mkOption {
519+ Number of seconds between reloads triggered by xfrd.
523+ zonefilesCheck = mkOption {
527+ Wheter to check mtime of all zone files on start and sighup.
533+ type = types.attrsOf (types.submodule {
536+ algorithm = mkOption {
538+ default = "hmac-sha256";
540+ Authentication algorithm for this key.
544+ keyFile = mkOption {
547+ Path to the file which contains the actual base64 encoded
548+ key. The key will be copied into "${stateDir}/private" before
549+ NSD starts. The copied file is only accessibly by the NSD
557+ example = literalExample ''
558+ { "tsig.example.org" = {
559+ algorithm = "hmac-md5";
560+ keyFile = "/path/to/my/key";
565+ Define your TSIG keys here.
371− hideVersion = mkOption {
569+
572+ enable = mkEnableOption "ratelimit capabilities";
574+ ipv4PrefixLength = mkOption {
372− type = types.bool;
575+ type = types.nullOr types.int;
373− default = true;
576+ default = null;
374 description = ''
577 description = ''
375− Wheter NSD should answer VERSION.BIND and VERSION.SERVER CHAOS class queries.
578+ IPv4 prefix length. Addresses are grouped by netblock.
379− identity = mkOption {
582+ ipv6PrefixLength = mkOption {
380− type = types.str;
583+ type = types.nullOr types.int;
381− default = "unidentified server";
584+ default = null;
382 description = ''
585 description = ''
383− Identify the server (CH TXT ID.SERVER entry).
586+ IPv6 prefix length. Addresses are grouped by netblock.
387− nsid = mkOption {
590+ ratelimit = mkOption {
388− type = types.nullOr types.str;
591+ type = types.int;
389− default = null;
592+ default = 200;
390 description = ''
593 description = ''
391− NSID identity (hex string, or "ascii_somestring").
594+ Max qps allowed from any query source.
595+ 0 means unlimited. With an verbosity of 2 blocked and
596+ unblocked subnets will be logged.
395− tcpCount = mkOption {
600+ slip = mkOption {
396− type = types.int;
601+ type = types.nullOr types.int;
397− default = 100;
602+ default = null;
398 description = ''
603 description = ''
399− Maximum number of concurrent TCP connections per server.
604+ Number of packets that get discarded before replying a SLIP response.
605+ 0 disables SLIP responses. 1 will make every response a SLIP response.
403− tcpQueryCount = mkOption {
609+ size = mkOption {
404− type = types.int;
610+ type = types.int;
405− default = 0;
611+ default = 1000000;
406 description = ''
612 description = ''
407− Maximum number of queries served on a single TCP connection.
613+ Size of the hashtable. More buckets use more memory but lower
408− 0 means no maximum.
614+ the chance of hash hash collisions.
412− tcpTimeout = mkOption {
618+ whitelistRatelimit = mkOption {
413− type = types.int;
619+ type = types.int;
414− default = 120;
620+ default = 2000;
415 description = ''
621 description = ''
416− TCP timeout in seconds.
622+ Max qps allowed from whitelisted sources.
623+ 0 means unlimited. Set the rrl-whitelist option for specific
624+ queries to apply this limit instead of the default to them.
420− ipv4EDNSSize = mkOption {
628+ };
633+ enable = mkEnableOption "remote control via nsd-control";
635+ controlCertFile = mkOption {
421− type = types.int;
636+ type = types.path;
422− default = 4096;
637+ default = "/etc/nsd/nsd_control.pem";
423 description = ''
638 description = ''
424− Preferred EDNS buffer size for IPv4.
639+ Path to the client certificate signed with the server certificate.
640+ This file is used by nsd-control and generated by nsd-control-setup.
428− ipv6EDNSSize = mkOption {
644+ controlKeyFile = mkOption {
429− type = types.int;
645+ type = types.path;
430− default = 4096;
646+ default = "/etc/nsd/nsd_control.key";
431 description = ''
647 description = ''
432− Preferred EDNS buffer size for IPv6.
648+ Path to the client private key, which is used by nsd-control
649+ but not by the server. This file is generated by nsd-control-setup.
436− statistics = mkOption {
653+ interfaces = mkOption {
437− type = types.nullOr types.int;
654+ type = types.listOf types.str;
438− default = null;
655+ default = [ "127.0.0.1" "::1" ];
439 description = ''
656 description = ''
440− Statistics are produced every number of seconds. Prints to log.
657+ Which interfaces NSD should bind to for remote control.
441− If null no statistics are logged.
445− xfrdReloadTimeout = mkOption {
661+ port = mkOption {
446− type = types.int;
662+ type = types.int;
447− default = 1;
663+ default = 8952;
448 description = ''
664 description = ''
449− Number of seconds between reloads triggered by xfrd.
665+ Port number for remote control operations (uses TLS over TCP).
453− zonefilesCheck = mkOption {
669+ serverCertFile = mkOption {
454− type = types.bool;
670+ type = types.path;
455− default = true;
671+ default = "/etc/nsd/nsd_server.pem";
456 description = ''
672 description = ''
457− Wheter to check mtime of all zone files on start and sighup.
673+ Path to the server self signed certificate, which is used by the server
674+ but and by nsd-control. This file is generated by nsd-control-setup.
462− extraConfig = mkOption {
678+ serverKeyFile = mkOption {
463− type = types.str;
679+ type = types.path;
464− default = "";
680+ default = "/etc/nsd/nsd_server.key";
465 description = ''
681 description = ''
466− Extra nsd config.
682+ Path to the server private key, which is used by the server
683+ but not by nsd-control. This file is generated by nsd-control-setup.
472− enable = mkEnableOption "ratelimit capabilities";
478− Size of the hashtable. More buckets use more memory but lower
479− the chance of hash hash collisions.
483− ratelimit = mkOption {
487− Max qps allowed from any query source.
488− 0 means unlimited. With an verbosity of 2 blocked and
489− unblocked subnets will be logged.
493− whitelistRatelimit = mkOption {
497− Max qps allowed from whitelisted sources.
498− 0 means unlimited. Set the rrl-whitelist option for specific
499− queries to apply this limit instead of the default to them.
504− type = types.nullOr types.int;
507− Number of packets that get discarded before replying a SLIP response.
508− 0 disables SLIP responses. 1 will make every response a SLIP response.
512− ipv4PrefixLength = mkOption {
513− type = types.nullOr types.int;
516− IPv4 prefix length. Addresses are grouped by netblock.
520− ipv6PrefixLength = mkOption {
521− type = types.nullOr types.int;
524− IPv6 prefix length. Addresses are grouped by netblock.
531− enable = mkEnableOption "remote control via nsd-control";
533− interfaces = mkOption {
534− type = types.listOf types.str;
535− default = [ "127.0.0.1" "::1" ];
537− Which interfaces NSD should bind to for remote control.
545− Port number for remote control operations (uses TLS over TCP).
549− serverKeyFile = mkOption {
551− default = "/etc/nsd/nsd_server.key";
553− Path to the server private key, which is used by the server
554− but not by nsd-control. This file is generated by nsd-control-setup.
558− serverCertFile = mkOption {
560− default = "/etc/nsd/nsd_server.pem";
562− Path to the server self signed certificate, which is used by the server
563− but and by nsd-control. This file is generated by nsd-control-setup.
567− controlKeyFile = mkOption {
569− default = "/etc/nsd/nsd_control.key";
571− Path to the client private key, which is used by nsd-control
572− but not by the server. This file is generated by nsd-control-setup.
576− controlCertFile = mkOption {
578− default = "/etc/nsd/nsd_control.pem";
580− Path to the client certificate signed with the server certificate.
581− This file is used by nsd-control and generated by nsd-control-setup.
588− type = types.attrsOf (types.submodule {
590− algorithm = mkOption {
592− default = "hmac-sha256";
594− Authentication algorithm for this key.
598− keyFile = mkOption {
690+ zones = mkOption {
599− type = types.path;
691+ type = types.attrsOf zoneOptions;
600− description = ''
692+ default = {};
601− Path to the file which contains the actual base64 encoded
693+ example = literalExample ''
602− key. The key will be copied into "${stateDir}/private" before
694+ { "serverGroup1" = {
603− NSD starts. The copied file is only accessibly by the NSD
695+ provideXFR = [ "10.1.2.3 NOKEY" ];
604− user.
696+ children = {
699+ $ORIGIN example.com.
701+ @ IN SOA a.ns.example.com. admin.example.com. (
707+ $ORIGIN example.org.
709+ @ IN SOA a.ns.example.com. admin.example.com. (
609− default = {};
716+ "example.net." = {
610− example = {
717+ provideXFR = [ "10.3.2.1 NOKEY" ];
611− "tsig.example.org" = {
718+ data = '''
612− algorithm = "hmac-md5";
719+ ...
613− secret = "aaaaaabbbbbbccccccdddddd";
720+ ''';
617− Define your TSIG keys here.
619− };
724+ description = ''
622− type = types.attrsOf zoneOptions;
624− example = literalExample ''
625− { "serverGroup1" = {
626− provideXFR = [ "10.1.2.3 NOKEY" ];
630− $ORIGIN example.com.
632− @ IN SOA a.ns.example.com. admin.example.com. (
638− $ORIGIN example.org.
640− @ IN SOA a.ns.example.com. admin.example.com. (
648− provideXFR = [ "10.3.2.1 NOKEY" ];
656− Define your zones here. Zones can cascade other zones and therefore
725+ Define your zones here. Zones can cascade other zones and therefore
657− inherit settings from parent zones. Look at the definition of
726+ inherit settings from parent zones. Look at the definition of
658− children to learn about inheritance and child zones.
727+ children to learn about inheritance and child zones.
659− The given example will define 3 zones (example.(com|org|net).). Both
728+ The given example will define 3 zones (example.(com|org|net).). Both
660− example.com. and example.org. inherit their configuration from
729+ example.com. and example.org. inherit their configuration from
661− serverGroup1.
730+ serverGroup1.
668 config = mkIf cfg.enable {
736 config = mkIf cfg.enable {
670 users.extraGroups = singleton {
738 users.extraGroups = singleton {
671 name = username;
739 name = username;
672− gid = config.ids.gids.nsd;
740+ gid = config.ids.gids.nsd;
675 users.extraUsers = singleton {
743 users.extraUsers = singleton {
676− name = username;
744+ name = username;
677 description = "NSD service user";
745 description = "NSD service user";
678− home = stateDir;
746+ home = stateDir;
679 createHome = true;
747 createHome = true;
680− uid = config.ids.uids.nsd;
748+ uid = config.ids.uids.nsd;
681− group = username;
749+ group = username;
684 systemd.services.nsd = {
752 systemd.services.nsd = {
685 description = "NSD authoritative only domain name service";
753 description = "NSD authoritative only domain name service";
755+ after = [ "keys.target" "network.target" ];
686− wantedBy = [ "multi-user.target" ];
756+ wantedBy = [ "multi-user.target" ];
687− after = [ "network.target" ];
757+ wants = [ "keys.target" ];
689 serviceConfig = {
759 serviceConfig = {
692− ExecStart = "${nsdPkg}/sbin/nsd -d -c ${configFile}";
760+ ExecStart = "${nsdPkg}/sbin/nsd -d -c ${nsdEnv}/nsd.conf";
764+ StartLimitBurst = 4;
765+ StartLimitInterval = "5min";
695 preStart = ''
768 preStart = ''
696− ${pkgs.coreutils}/bin/mkdir -m 0700 -p "${stateDir}/private"
769+ rm -Rf "${stateDir}/private/"
697− ${pkgs.coreutils}/bin/mkdir -m 0700 -p "${stateDir}/tmp"
770+ rm -Rf "${stateDir}/tmp/"
698− ${pkgs.coreutils}/bin/mkdir -m 0700 -p "${stateDir}/var"
700− ${pkgs.coreutils}/bin/touch "${stateDir}/don't touch anything in here"
772+ mkdir -m 0700 -p "${stateDir}/private"
773+ mkdir -m 0700 -p "${stateDir}/tmp"
774+ mkdir -m 0700 -p "${stateDir}/var"
702− ${pkgs.coreutils}/bin/rm -f "${stateDir}/private/"*
776+ cat > "${stateDir}/don't touch anything in here" << EOF
703− ${pkgs.coreutils}/bin/rm -f "${stateDir}/tmp/"*
777+ Everything in this directory except NSD's state in var is
778+ automatically generated and will be purged and redeployed
779+ by the nsd.service pre-start script.
705− ${pkgs.coreutils}/bin/chown nsd:nsd -R "${stateDir}/private"
782+ chown ${username}:${username} -R "${stateDir}/private"
706− ${pkgs.coreutils}/bin/chown nsd:nsd -R "${stateDir}/tmp"
783+ chown ${username}:${username} -R "${stateDir}/tmp"
707− ${pkgs.coreutils}/bin/chown nsd:nsd -R "${stateDir}/var"
784+ chown ${username}:${username} -R "${stateDir}/var"
709− ${pkgs.coreutils}/bin/rm -rf "${stateDir}/zones"
786+ rm -rf "${stateDir}/zones"
710− ${pkgs.coreutils}/bin/cp -r "${zoneFiles}" "${stateDir}/zones"
787+ cp -rL "${nsdEnv}/zones" "${stateDir}/zones"
712 ${copyKeys}
789 ${copyKeys}