blob: e837f89cc10338842bbccca45b20102611f5cacf (
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
{
config,
inputs,
lib,
pkgs,
this,
...
}:
with lib;
let
cfg = config.nixfiles.modules.unbound;
in
{
options.nixfiles.modules.unbound = {
enable = mkEnableOption "Unbound";
domain = mkOption {
description = "Domain name sans protocol scheme.";
type = with types; str;
default = config.networking.domain;
};
};
config = mkIf cfg.enable {
ark.directories = [ config.services.unbound.stateDir ];
nixfiles.modules.redis.enable = true;
services = {
unbound = {
enable = true;
package = pkgs.unbound-with-systemd.override {
withRedis = true;
withTFO = true;
};
checkconf = true;
settings = {
server = {
module-config = ''"respip validator iterator"'';
interface = with this.wireguard; [
"127.0.0.1"
"::1"
ipv4.address
ipv6.address
];
local-zone = concatLists (
mapAttrsToList (h: _: [ "\"${h}.${cfg.domain}\" redirect" ]) my.configurations
);
local-data = concatLists (
mapAttrsToList (
hostname:
let
domain = "${hostname}.${cfg.domain}";
in
attr:
(optionals (hasAttr "wireguard" attr) (
with attr.wireguard;
[
"\"${domain} 604800 IN A ${ipv4.address}\""
"\"${domain} 604800 IN AAAA ${ipv6.address}\""
"\"${domain}. A ${ipv4.address}\""
"\"${domain}. AAAA ${ipv6.address}\""
]
++ concatMap (domain: [
"\"${domain}. A ${ipv4.address}\""
"\"${domain}. AAAA ${ipv6.address}\""
]) attr.domains
))
) my.configurations
);
local-data-ptr = concatLists (
mapAttrsToList (
hostname:
let
domain = "${hostname}.${cfg.domain}";
in
attr:
(optionals (hasAttr "wireguard" attr) (
with attr.wireguard;
[
"\"${ipv4.address} ${domain}\""
"\"${ipv6.address} ${domain}\""
]
++ concatMap (domain: [
"\"${ipv4.address} ${domain}\""
"\"${ipv6.address} ${domain}\""
]) attr.domains
))
) my.configurations
);
private-domain = map (domain: "${domain}.") [
cfg.domain
"local"
];
private-address = with config.nixfiles.modules.wireguard; [
ipv4.subnet
ipv6.subnet
];
access-control = with config.nixfiles.modules.wireguard; [
"0.0.0.0/0 refuse"
"::/0 refuse"
"127.0.0.0/8 allow"
"::1/128 allow"
"${ipv4.subnet} allow"
"${ipv6.subnet} allow"
];
cache-min-ttl = 0;
serve-expired = true;
serve-expired-reply-ttl = 0;
prefetch = true;
prefetch-key = true;
hide-identity = true;
hide-version = true;
extended-statistics = true;
log-replies = false;
log-tag-queryreply = false;
log-local-actions = false;
verbosity = 0;
};
forward-zone = [
{
name = ".";
forward-tls-upstream = true;
forward-addr = dns.mkDoT dns.const.quad9.ecs;
}
];
cachedb = with config.services.redis.servers.default; {
backend = "redis";
redis-server-host = bind;
redis-server-port = port;
};
rpz = {
name = "hagezi.pro";
zonefile = "hagezi.pro";
url = "https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/rpz/pro.txt";
};
};
enableRootTrustAnchor = true;
localControlSocketPath = "/run/unbound/unbound.socket";
};
prometheus.exporters.unbound = {
enable = true;
listenAddress = mkDefault this.wireguard.ipv4.address;
port = 9167;
inherit (config.services.unbound) group user;
unbound.host = "unix://${config.services.unbound.localControlSocketPath}";
};
};
boot.kernel.sysctl."net.ipv4.tcp_fastopen" = mkOverride 200 3;
topology = with cfg; {
nodes.${this.hostname}.services.unbound = {
name = "Unbound";
icon = "${inputs.homelab-svg-assets}/assets/unbound.svg";
details.listen.text = concatMapStringsSep "\n" (i: "${i}:53") (
filter (i: i != "127.0.0.1" && i != "::1") config.services.unbound.settings.server.interface
);
};
};
};
}
|