2009-10-12 16:36:19 +00:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
2009-03-06 12:27:13 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
startingDependency = if config.services.gw6c.enable then "gw6c" else "network-interfaces";
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
cfg = config.services.bind;
|
|
|
|
|
|
|
|
confFile = pkgs.writeText "named.conf"
|
|
|
|
''
|
|
|
|
acl cachenetworks { ${concatMapStrings (entry: " ${entry}; ") cfg.cacheNetworks} };
|
|
|
|
acl badnetworks { ${concatMapStrings (entry: " ${entry}; ") cfg.blockedNetworks} };
|
|
|
|
|
|
|
|
options {
|
|
|
|
listen-on {any;};
|
|
|
|
listen-on-v6 {any;};
|
|
|
|
allow-query { cachenetworks; };
|
|
|
|
blackhole { badnetworks; };
|
|
|
|
forward first;
|
|
|
|
forwarders { ${concatMapStrings (entry: " ${entry}; ") config.networking.nameservers} };
|
|
|
|
directory "/var/run/named";
|
|
|
|
pid-file "/var/run/named/named.pid";
|
2009-03-06 12:27:13 +00:00
|
|
|
};
|
2009-10-12 16:36:19 +00:00
|
|
|
|
|
|
|
${ concatMapStrings
|
|
|
|
({ name, file, master ? true, slaves ? [], masters ? [] }:
|
2011-09-14 18:20:50 +00:00
|
|
|
''
|
2009-10-12 16:36:19 +00:00
|
|
|
zone "${name}" {
|
|
|
|
type ${if master then "master" else "slave"};
|
|
|
|
file "${file}";
|
|
|
|
${ if master then
|
|
|
|
''
|
|
|
|
allow-transfer {
|
|
|
|
${concatMapStrings (ip: "${ip};\n") slaves}
|
|
|
|
};
|
|
|
|
''
|
|
|
|
else
|
|
|
|
''
|
|
|
|
masters {
|
|
|
|
${concatMapStrings (ip: "${ip};\n") masters}
|
|
|
|
};
|
|
|
|
''
|
|
|
|
}
|
|
|
|
allow-query { any; };
|
|
|
|
};
|
|
|
|
'')
|
|
|
|
cfg.zones }
|
|
|
|
'';
|
|
|
|
|
2009-03-06 12:27:13 +00:00
|
|
|
in
|
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
{
|
2009-03-06 12:27:13 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
services.bind = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "
|
|
|
|
Whether to enable BIND domain name server.
|
|
|
|
";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
cacheNetworks = mkOption {
|
|
|
|
default = ["127.0.0.0/24"];
|
|
|
|
description = "
|
|
|
|
What networks are allowed to use us as a resolver.
|
|
|
|
";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
blockedNetworks = mkOption {
|
|
|
|
default = [];
|
|
|
|
description = "
|
|
|
|
What networks are just blocked.
|
|
|
|
";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
zones = mkOption {
|
|
|
|
default = [];
|
|
|
|
description = "
|
|
|
|
List of zones we claim authority over.
|
2011-09-14 18:20:50 +00:00
|
|
|
master=false means slave server; slaves means addresses
|
2009-10-12 16:36:19 +00:00
|
|
|
who may request zone transfer.
|
|
|
|
";
|
|
|
|
example = [{
|
|
|
|
name = "example.com";
|
|
|
|
master = false;
|
|
|
|
file = "/var/dns/example.com";
|
|
|
|
masters = ["192.168.0.1"];
|
|
|
|
slaves = [];
|
|
|
|
}];
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2008-07-01 12:15:56 +00:00
|
|
|
};
|
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2008-07-01 12:15:56 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
###### implementation
|
2008-07-01 12:15:56 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
config = mkIf config.services.bind.enable {
|
2009-03-06 12:27:13 +00:00
|
|
|
|
2009-10-12 18:09:34 +00:00
|
|
|
jobs.bind =
|
2009-10-12 16:36:19 +00:00
|
|
|
{ description = "BIND name server job";
|
2009-03-06 12:27:13 +00:00
|
|
|
|
2009-10-12 16:36:19 +00:00
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
${pkgs.coreutils}/bin/mkdir -p /var/run/named
|
|
|
|
'';
|
|
|
|
|
|
|
|
exec = "${pkgs.bind}/sbin/named -c ${confFile} -f";
|
|
|
|
};
|
2008-07-01 12:15:56 +00:00
|
|
|
|
2009-03-06 12:27:13 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-03-06 12:27:13 +00:00
|
|
|
}
|