dnscache service: cleanup and add forwardOnly

This commit is contained in:
Nikolay Amiantov 2018-04-13 15:30:57 +03:00
parent 98270cb959
commit dccd5a8601
1 changed files with 23 additions and 6 deletions

View File

@ -9,7 +9,7 @@ let
mkdir -p $out/{servers,ip} mkdir -p $out/{servers,ip}
${concatMapStrings (ip: '' ${concatMapStrings (ip: ''
echo > "$out/ip/"${lib.escapeShellArg ip} touch "$out/ip/"${lib.escapeShellArg ip}
'') cfg.clientIps} '') cfg.clientIps}
${concatStrings (mapAttrsToList (host: ips: '' ${concatStrings (mapAttrsToList (host: ips: ''
@ -34,33 +34,49 @@ in {
options = { options = {
services.dnscache = { services.dnscache = {
enable = mkOption { enable = mkOption {
default = false; default = false;
type = types.bool; type = types.bool;
description = "Whether to run the dnscache caching dns server"; description = "Whether to run the dnscache caching dns server.";
}; };
ip = mkOption { ip = mkOption {
default = "0.0.0.0"; default = "0.0.0.0";
type = types.str; type = types.str;
description = "IP address on which to listen for connections"; description = "IP address on which to listen for connections.";
}; };
clientIps = mkOption { clientIps = mkOption {
default = [ "127.0.0.1" ]; default = [ "127.0.0.1" ];
type = types.listOf types.str; type = types.listOf types.str;
description = "client IP addresses (or prefixes) from which to accept connections"; description = "Client IP addresses (or prefixes) from which to accept connections.";
example = ["192.168" "172.23.75.82"]; example = ["192.168" "172.23.75.82"];
}; };
domainServers = mkOption { domainServers = mkOption {
default = { }; default = { };
type = types.attrsOf (types.listOf types.str); type = types.attrsOf (types.listOf types.str);
description = "table of {hostname: server} pairs to use as authoritative servers for hosts (and subhosts)"; description = ''
Table of {hostname: server} pairs to use as authoritative servers for hosts (and subhosts).
If entry for @ is not specified predefined list of root servers is used.
'';
example = { example = {
"example.com" = ["8.8.8.8" "8.8.4.4"]; "@" = ["8.8.8.8" "8.8.4.4"];
"example.com" = ["192.168.100.100"];
}; };
}; };
forwardOnly = mkOption {
default = false;
type = types.bool;
description = ''
Whether to treat root servers (for @) as caching
servers, requesting addresses the same way a client does. This is
needed if you want to use e.g. Google DNS as your upstream DNS.
'';
};
}; };
}; };
@ -82,6 +98,7 @@ in {
''; '';
script = '' script = ''
cd /var/lib/dnscache/ cd /var/lib/dnscache/
${optionalString cfg.forwardOnly "export FORWARDONLY=1"}
exec ./run exec ./run
''; '';
}; };