git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #29450 from jerith666/djb-1709

Add modules for tinydns and dnscache from djbdns

commit975c7b22044e7d1568efa2b01d46a4fc917420c7 authorJörg Thalheim <Mic92@users.noreply.github.com> dateSun 24 Sep 2017, 15:39 (9 years ago) parent412fa16735b41c
6 files changed+207
nixos/modules/module-list.nix+2 nixos/modules/services/networking/dnscache.nix+86 nixos/modules/services/networking/tinydns.nix+54 pkgs/tools/networking/djbdns/default.nix+48 pkgs/tools/networking/djbdns/hier.patch+15 pkgs/top-level/all-packages.nix+2
nixos/modules/module-list.nix+2
@@ -426,6 +426,7 @@
426426 ./services/networking/ddclient.nix
427427 ./services/networking/dhcpcd.nix
428428 ./services/networking/dhcpd.nix
429+ ./services/networking/dnscache.nix
429430 ./services/networking/dnschain.nix
430431 ./services/networking/dnscrypt-proxy.nix
431432 ./services/networking/dnscrypt-wrapper.nix
@@ -526,6 +527,7 @@
526527 ./services/networking/tcpcrypt.nix
527528 ./services/networking/teamspeak3.nix
528529 ./services/networking/tinc.nix
530+ ./services/networking/tinydns.nix
529531 ./services/networking/tftpd.nix
530532 ./services/networking/tox-bootstrapd.nix
531533 ./services/networking/toxvpn.nix
nixos/modules/services/networking/dnscache.nixnew file+86
@@ -0,0 +1,86 @@
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+}
nixos/modules/services/networking/tinydns.nixnew file+54
@@ -0,0 +1,54 @@
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+}
pkgs/tools/networking/djbdns/default.nixnew file+48
@@ -0,0 +1,48 @@
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+}
pkgs/tools/networking/djbdns/hier.patchnew file+15
@@ -0,0 +1,15 @@
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);
pkgs/top-level/all-packages.nix+2
@@ -1671,6 +1671,8 @@ with pkgs;
16711671
16721672 dev86 = callPackage ../development/compilers/dev86 { };
16731673
1674+ djbdns = callPackage ../tools/networking/djbdns { };
1675+
16741676 dnscrypt-proxy = callPackage ../tools/networking/dnscrypt-proxy { };
16751677
16761678 dnscrypt-wrapper = callPackage ../tools/networking/dnscrypt-wrapper { };