-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathadguardhome.nix
142 lines (135 loc) · 3.99 KB
/
adguardhome.nix
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
{
config,
globals,
lib,
...
}:
let
adguardhomeDomain = "adguardhome.${globals.domains.me}";
in
{
wireguard.proxy-sentinel = {
client.via = "sentinel";
firewallRuleForNode.sentinel.allowedTCPPorts = [ config.services.adguardhome.port ];
};
# Allow home-assistant to access it directly
wireguard.proxy-home = {
client.via = "ward";
firewallRuleForNode.sausebiene.allowedTCPPorts = [ config.services.adguardhome.port ];
};
globals.services.adguardhome.domain = adguardhomeDomain;
globals.monitoring.dns.adguardhome = {
server = globals.net.home-lan.vlans.services.hosts.ward-adguardhome.ipv4;
domain = ".";
network = "home-lan.vlans.services";
};
nodes.sentinel = {
services.nginx = {
upstreams.adguardhome = {
servers."${config.wireguard.proxy-sentinel.ipv4}:${toString config.services.adguardhome.port}" =
{ };
extraConfig = ''
zone adguardhome 64k;
keepalive 2;
'';
monitoring = {
enable = true;
expectedBodyRegex = "AdGuard Home";
};
};
virtualHosts.${adguardhomeDomain} = {
forceSSL = true;
useACMEWildcardHost = true;
oauth2.enable = true;
oauth2.allowedGroups = [ "access_adguardhome" ];
locations."/" = {
proxyPass = "http://adguardhome";
proxyWebsockets = true;
};
};
};
};
environment.persistence."/persist".directories = [
{
directory = "/var/lib/private/AdGuardHome";
mode = "0700";
}
];
networking.firewall = {
allowedTCPPorts = [ 53 ];
allowedUDPPorts = [ 53 ];
};
topology.self.services.adguardhome.info = "https://" + adguardhomeDomain;
services.adguardhome = {
enable = true;
mutableSettings = false;
host = "0.0.0.0";
port = 3000;
settings = {
dns = {
bind_hosts = [ globals.net.home-lan.vlans.services.hosts.ward-adguardhome.ipv4 ];
# allowed_clients = [
# ];
#trusted_proxies = [];
ratelimit = 300;
upstream_dns = [
"https://dns.cloudflare.com/dns-query"
"https://dns.google/dns-query"
"https://doh.mullvad.net/dns-query"
];
bootstrap_dns = [
"1.1.1.1"
# FIXME: enable ipv6 "2606:4700:4700::1111"
"8.8.8.8"
# FIXME: enable ipv6 "2001:4860:4860::8844"
];
dhcp.enabled = false;
};
filtering.rewrites =
[
# Undo the /etc/hosts entry so we don't answer with the internal
# wireguard address for influxdb
{
inherit (globals.services.influxdb) domain;
answer = globals.domains.me;
}
]
# Use the local mirror-proxy for some services (not necessary, just for speed)
++
map
(domain: {
inherit domain;
answer = globals.net.home-lan.vlans.services.hosts.ward-web-proxy.ipv4;
})
[
# FIXME: dont hardcode, filter global service domains by internal state
globals.services.grafana.domain
globals.services.immich.domain
globals.services.influxdb.domain
globals.services.loki.domain
globals.services.paperless.domain
globals.services.esphome.domain
globals.services.home-assistant.domain
"fritzbox.${globals.domains.personal}"
];
filters = [
{
name = "AdGuard DNS filter";
url = "https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt";
enabled = true;
}
{
name = "AdAway Default Blocklist";
url = "https://adaway.org/hosts.txt";
enabled = true;
}
{
name = "OISD (Big)";
url = "https://big.oisd.nl";
enabled = true;
}
];
};
};
systemd.services.adguardhome.serviceConfig.RestartSec = lib.mkForce "60"; # Retry every minute
}