Merge pull request #29450 from jerith666/djb-1709

Add modules for tinydns and dnscache from djbdns

authored by Jörg Thalheim and committed by GitHub 975c7b22 412fa16b

+207
+2
nixos/modules/module-list.nix
··· 426 426 ./services/networking/ddclient.nix 427 427 ./services/networking/dhcpcd.nix 428 428 ./services/networking/dhcpd.nix 429 + ./services/networking/dnscache.nix 429 430 ./services/networking/dnschain.nix 430 431 ./services/networking/dnscrypt-proxy.nix 431 432 ./services/networking/dnscrypt-wrapper.nix ··· 526 527 ./services/networking/tcpcrypt.nix 527 528 ./services/networking/teamspeak3.nix 528 529 ./services/networking/tinc.nix 530 + ./services/networking/tinydns.nix 529 531 ./services/networking/tftpd.nix 530 532 ./services/networking/tox-bootstrapd.nix 531 533 ./services/networking/toxvpn.nix
+86
nixos/modules/services/networking/dnscache.nix
··· 1 + { config, lib, pkgs, ... }: 2 + 3 + with lib; 4 + 5 + let 6 + cfg = config.services.dnscache; 7 + 8 + dnscache-root = pkgs.runCommand "dnscache-root" {} '' 9 + mkdir -p $out/{servers,ip} 10 + 11 + ${concatMapStrings (ip: '' 12 + echo > "$out/ip/"${lib.escapeShellArg ip} 13 + '') cfg.clientIps} 14 + 15 + ${concatStrings (mapAttrsToList (host: ips: '' 16 + ${concatMapStrings (ip: '' 17 + echo ${lib.escapeShellArg ip} > "$out/servers/"${lib.escapeShellArg host} 18 + '') ips} 19 + '') cfg.domainServers)} 20 + 21 + # djbdns contains an outdated list of root servers; 22 + # if one was not provided in config, provide a current list 23 + if [ ! -e servers/@ ]; then 24 + awk '/^.?.ROOT-SERVERS.NET/ { print $4 }' ${pkgs.dns-root-data}/root.hints > $out/servers/@ 25 + fi 26 + ''; 27 + 28 + in { 29 + 30 + ###### interface 31 + 32 + options = { 33 + services.dnscache = { 34 + enable = mkOption { 35 + default = false; 36 + type = types.bool; 37 + description = "Whether to run the dnscache caching dns server"; 38 + }; 39 + 40 + ip = mkOption { 41 + default = "0.0.0.0"; 42 + type = types.str; 43 + description = "IP address on which to listen for connections"; 44 + }; 45 + 46 + clientIps = mkOption { 47 + default = [ "127.0.0.1" ]; 48 + type = types.listOf types.str; 49 + description = "client IP addresses (or prefixes) from which to accept connections"; 50 + example = ["192.168" "172.23.75.82"]; 51 + }; 52 + 53 + domainServers = mkOption { 54 + default = { }; 55 + type = types.attrsOf (types.listOf types.str); 56 + description = "table of {hostname: server} pairs to use as authoritative servers for hosts (and subhosts)"; 57 + example = { 58 + "example.com" = ["8.8.8.8" "8.8.4.4"]; 59 + }; 60 + }; 61 + }; 62 + }; 63 + 64 + ###### implementation 65 + 66 + config = mkIf config.services.dnscache.enable { 67 + environment.systemPackages = [ pkgs.djbdns ]; 68 + users.extraUsers.dnscache = {}; 69 + 70 + systemd.services.dnscache = { 71 + description = "djbdns dnscache server"; 72 + wantedBy = [ "multi-user.target" ]; 73 + path = with pkgs; [ bash daemontools djbdns ]; 74 + preStart = '' 75 + rm -rf /var/lib/dnscache 76 + dnscache-conf dnscache dnscache /var/lib/dnscache ${config.services.dnscache.ip} 77 + rm -rf /var/lib/dnscache/root 78 + ln -sf ${dnscache-root} /var/lib/dnscache/root 79 + ''; 80 + script = '' 81 + cd /var/lib/dnscache/ 82 + exec ./run 83 + ''; 84 + }; 85 + }; 86 + }
+54
nixos/modules/services/networking/tinydns.nix
··· 1 + { config, lib, pkgs, ... }: 2 + 3 + with lib; 4 + 5 + { 6 + ###### interface 7 + 8 + options = { 9 + services.tinydns = { 10 + enable = mkOption { 11 + default = false; 12 + type = types.bool; 13 + description = "Whether to run the tinydns dns server"; 14 + }; 15 + 16 + data = mkOption { 17 + type = types.lines; 18 + default = ""; 19 + description = "The DNS data to serve, in the format described by tinydns-data(8)"; 20 + }; 21 + 22 + ip = mkOption { 23 + default = "0.0.0.0"; 24 + type = types.str; 25 + description = "IP address on which to listen for connections"; 26 + }; 27 + }; 28 + }; 29 + 30 + ###### implementation 31 + 32 + config = mkIf config.services.tinydns.enable { 33 + environment.systemPackages = [ pkgs.djbdns ]; 34 + 35 + users.extraUsers.tinydns = {}; 36 + 37 + systemd.services.tinydns = { 38 + description = "djbdns tinydns server"; 39 + wantedBy = [ "multi-user.target" ]; 40 + path = with pkgs; [ daemontools djbdns ]; 41 + preStart = '' 42 + rm -rf /var/lib/tinydns 43 + tinydns-conf tinydns tinydns /var/lib/tinydns ${config.services.tinydns.ip} 44 + cd /var/lib/tinydns/root/ 45 + ln -sf ${pkgs.writeText "tinydns-data" config.services.tinydns.data} data 46 + tinydns-data 47 + ''; 48 + script = '' 49 + cd /var/lib/tinydns 50 + exec ./run 51 + ''; 52 + }; 53 + }; 54 + }
+48
pkgs/tools/networking/djbdns/default.nix
··· 1 + { stdenv, fetchurl, glibc } : 2 + 3 + let 4 + version = "1.05"; 5 + 6 + manSrc = fetchurl { 7 + url = "http://smarden.org/pape/djb/manpages/djbdns-${version}-man-20031023.tar.gz"; 8 + sha256 = "0sg51gjy6j1hnrra406q1qhf5kvk1m00y8qqhs6r0a699gqmh75s"; 9 + }; 10 + 11 + in 12 + 13 + stdenv.mkDerivation { 14 + name = "djbdns-${version}"; 15 + 16 + src = fetchurl { 17 + url = "https://cr.yp.to/djbdns/djbdns-${version}.tar.gz"; 18 + sha256 = "0j3baf92vkczr5fxww7rp1b7gmczxmmgrqc8w2dy7kgk09m85k9w"; 19 + }; 20 + 21 + patches = [ ./hier.patch ]; 22 + 23 + postPatch = '' 24 + echo gcc -O2 -include ${glibc.dev}/include/errno.h > conf-cc 25 + echo $out > conf-home 26 + sed -i "s|/etc/dnsroots.global|$out/etc/dnsroots.global|" dnscache-conf.c 27 + ''; 28 + 29 + installPhase = '' 30 + mkdir -pv $out/etc; 31 + make setup 32 + cd $out; 33 + tar xzvf ${manSrc}; 34 + for n in 1 5 8; do 35 + mkdir -p man/man$n; 36 + mv -iv djbdns-man/*.$n man/man$n; 37 + done; 38 + rm -rv djbdns-man; 39 + ''; 40 + 41 + meta = with stdenv.lib; { 42 + description = "A collection of Domain Name System tools"; 43 + longDescription = "Includes software for all the fundamental DNS operations: DNS cache: finding addresses of Internet hosts; DNS server: publishing addresses of Internet hosts; and DNS client: talking to a DNS cache."; 44 + homepage = https://cr.yp.to/djbdns.html; 45 + license = licenses.publicDomain; 46 + maintainers = with maintainers; [ jerith666 ]; 47 + }; 48 + }
+15
pkgs/tools/networking/djbdns/hier.patch
··· 1 + --- a/hier.c 2016-04-19 21:22:21.992192405 -0400 2 + +++ b/hier.c 2016-04-19 21:22:33.160229778 -0400 3 + @@ -2,9 +2,9 @@ 4 + 5 + void hier() 6 + { 7 + - c("/","etc","dnsroots.global",-1,-1,0644); 8 + + c(auto_home,"etc","dnsroots.global",-1,-1,0644); 9 + 10 + - h(auto_home,-1,-1,02755); 11 + - d(auto_home,"bin",-1,-1,02755); 12 + + h(auto_home,-1,-1,0755); 13 + + d(auto_home,"bin",-1,-1,0755); 14 + 15 + c(auto_home,"bin","dnscache-conf",-1,-1,0755);
+2
pkgs/top-level/all-packages.nix
··· 1671 1671 1672 1672 dev86 = callPackage ../development/compilers/dev86 { }; 1673 1673 1674 + djbdns = callPackage ../tools/networking/djbdns { }; 1675 + 1674 1676 dnscrypt-proxy = callPackage ../tools/networking/dnscrypt-proxy { }; 1675 1677 1676 1678 dnscrypt-wrapper = callPackage ../tools/networking/dnscrypt-wrapper { };