summaryrefslogtreecommitdiff
path: root/hosts/kay/modules/dns/default.nix
blob: 1146cc342d717d599ebc23e72ed9da90099f8647 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
{ config, pkgs, ... }: let
  listen_addr = "2001:470:ee65::1";

  acmeSOA = pkgs.writeText "acmeSOA" ''
    $TTL 2d

    @	IN	SOA	ns1.sinanmohd.com.	sinan.sinanmohd.com. (
                        2024020505 ; serial
                        2h         ; refresh
                        5m         ; retry
                        1d         ; expire
                        5m )       ; nx ttl

        IN	NS	ns1.sinanmohd.com.
  '';
in {
  imports = [ ./ddns.nix ];

  networking.firewall = {
    allowedTCPPorts = [ 53 ];
    allowedUDPPorts = [ 53 ];
  };

  sops.secrets.dns = {
    owner = config.systemd.services.knot.serviceConfig.User;
    group = config.systemd.services.knot.serviceConfig.Group;
  };

  services.knot = {
    enable = true;
    keyFiles = [ config.sops.secrets.dns.path ];

    settings = {
      server.listen = listen_addr;

      remote = [
        {
          id = "ns1.he.net";
          address = [ "2001:470:100::2" "216.218.130.2" ];
          via = "2001:470:ee65::1";
        }
        {
          id = "m.gtld-servers.net";
          address = [ "2001:501:b1f9::30"  "192.55.83.30" ];
        }
      ];

      submission = [{
        id = "gtld-servers.net";
        parent = "m.gtld-servers.net";
      }];

      policy = [{
        id = "gtld-servers.net";
        algorithm = "ecdsap384sha384";
        ksk-lifetime = "365d";
        ksk-submission = "gtld-servers.net";
      }];

      # generate TSIG key with keymgr -t name
      acl = [
        {
          id = "ns1.he.net";
          key = "ns1.he.net";
          address = [ "2001:470:600::2" "216.218.133.2" ];
          action = "transfer";
        }
        {
          id = "localhost";
          address = [ listen_addr ];
          update-type = [ "A" "AAAA" ];
          action = "update";
        }
        {
          id = "acme";
          address = [ listen_addr ];
          update-type = [ "TXT" ];
          action = "update";
        }
      ];

      mod-rrl = [{
        id = "default";
        rate-limit = 200;
        slip = 2;
      }];

      template = [
        {
          id = "default";
          semantic-checks = "on";
          global-module = "mod-rrl/default";
        }
        {
          id = "master";
          semantic-checks = "on";

          dnssec-signing = "on";
          dnssec-policy = "gtld-servers.net";

          notify = [ "ns1.he.net" ];
          acl = [ "ns1.he.net" "localhost" ];

          zonefile-sync = "-1";
          zonefile-load = "difference";
        }
        {
          id = "acme";
          semantic-checks = "on";
          acl = [ "acme" ];

          zonefile-sync = "-1";
          zonefile-load = "difference";
          journal-content = "changes";
        }
      ];

      zone = [
        {
          domain = "sinanmohd.com";
          file = ./sinanmohd.com.zone;
          template = "master";
        }
        {
          domain = "_acme-challenge.sinanmohd.com";
          file = acmeSOA;
          template = "acme";
        }
        {
          domain = "5.6.e.e.0.7.4.0.1.0.0.2.ip6.arpa";
          file = ./5.6.e.e.0.7.4.0.1.0.0.2.ip6.arpa.zone;
        }
      ];
    };
  };

}