-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdns.mod.nix
More file actions
160 lines (148 loc) · 4.4 KB
/
Copy pathdns.mod.nix
File metadata and controls
160 lines (148 loc) · 4.4 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
{ self, lib, ... }:
{
flake.commonModules.dns =
{ config, pkgs, ... }:
let
inherit (lib.attrsets) getAttr;
inherit (lib.lists)
concatMap
imap0
singleton
sort
;
inherit (lib.strings) hasInfix substring;
mkSocketAddr =
{ ip, port }: if hasInfix ":" ip then "[${ip}]:${toString port}" else "${ip}:${toString port}";
id = "7f2bf8";
idv6 = "${substring 0 2 id}:${substring 2 4 id}";
mkNextDnsServers =
{ ip, hostName }:
[
{
socket_addr = mkSocketAddr {
inherit ip;
port = 443;
};
protocol = "h3";
tls_dns_name = "dns.nextdns.io";
http_endpoint = "/${id}/${hostName}";
trust_negative_responses = true;
}
{
socket_addr = mkSocketAddr {
inherit ip;
port = 853;
};
protocol = "quic";
tls_dns_name = "${hostName}-${id}.dns.nextdns.io";
trust_negative_responses = true;
}
{
socket_addr = mkSocketAddr {
inherit ip;
port = 443;
};
protocol = "https";
tls_dns_name = "dns.nextdns.io";
http_endpoint = "/${id}/${hostName}";
trust_negative_responses = true;
}
{
socket_addr = mkSocketAddr {
inherit ip;
port = 853;
};
protocol = "tls";
tls_dns_name = "${hostName}-${id}.dns.nextdns.io";
trust_negative_responses = true;
}
];
in
{
services.hickory-dns = {
enable = true;
package = pkgs.hickory-dns.overrideAttrs (old: {
cargoBuildFeatures = (old.cargoBuildFeatures or [ ]) ++ [
"tls-aws-lc-rs"
"https-aws-lc-rs"
"quic-aws-lc-rs"
"h3-aws-lc-rs"
];
meta.mainProgram = "hickory-dns"; # upstream does not seem to believe in mainProgram
meta.platforms = old.meta.platforms ++ lib.platforms.darwin;
});
settings = {
listen_port = 53;
listen_addrs_ipv6 = singleton "::";
zones = singleton {
zone = ".";
zone_type = "External";
stores.type = "forward";
stores.name_servers =
[
# { # FIXME: Slow.
# inherit (config.networking) hostName;
# ip = "2a07:a8c0::${idv6}";
# }
# {
# inherit (config.networking) hostName;
# ip = "2a07:a8c1::${idv6}";
# }
# {
# inherit (config.networking) hostName;
# ip = "45.90.28.0";
# }
{
inherit (config.networking) hostName;
ip = "45.90.30.0";
}
]
|> concatMap mkNextDnsServers
|> imap0 (index: server: { inherit index server; })
|> sort (
a: b:
let
protocolPriority =
protocol:
if protocol == "h3" then
0
else if protocol == "quic" then
1
else if protocol == "https" then
2
else if protocol == "tls" then
3
else
67;
aPriority = protocolPriority a.server.protocol;
bPriority = protocolPriority b.server.protocol;
in
if aPriority == bPriority then a.index < b.index else aPriority < bPriority
)
|> map (getAttr "server");
};
};
};
};
flake.darwinModules.dns =
{ lib, ... }:
let
inherit (lib.lists) singleton;
in
{
networking.dns = singleton "::1";
};
flake.nixosModules.dns =
{ lib, ... }:
let
inherit (lib.modules) mkForce;
in
{
services.resolved.enable = false;
environment.etc."resolv.conf".text = mkForce /* resolvconf */ ''
# Generated by NixOS modules, should use the Hickory-DNS forwarder.
options edns0 trust-ad
nameserver ::1
'';
};
}