1
0
Fork 0
dotfiles/system/nixos/adguardhome.nix

187 lines
4.1 KiB
Nix
Raw Permalink Normal View History

2023-06-07 18:40:27 +00:00
{ lib, config, secret, ... }:
2023-05-15 20:11:58 +00:00
{
services.adguardhome = {
enable = true;
2023-08-07 19:38:01 +00:00
mutableSettings = true;
2024-05-22 20:57:56 +00:00
# settings = null;
settings =
let
inherit (config.security.acme) certs;
in
{
tls = {
enabled = true;
port_https = 10443;
port_dns_over_tls = 1053;
port_dns_over_quic = 1053;
port_dnscrypt = 0;
certificate_path = "${certs."dns.kempkens.network".directory}/fullchain.pem";
private_key_path = "${certs."dns.kempkens.network".directory}/key.pem";
server_name = "dns.kempkens.network";
allow_unencrypted_doh = true;
strict_sni_check = true;
};
2024-05-25 13:47:17 +00:00
dns = {
# Based on: https://pkg.go.dev/github.com/Potterli20/golibs-fork/netutil#IsLocallyServed
private_networks = [
"10.0.0.0/8"
"127.0.0.0/8"
"169.254.0.0/16"
"172.16.0.0/12"
"192.0.2.0/24"
"192.168.0.0/16"
"198.51.100.0/24"
"203.0.113.0/24"
"255.255.255.255/32"
"::/128"
"::1/128"
"2001:db8::/32"
"fd00::/8"
"fe80::/10"
2024-07-18 21:07:07 +00:00
"100.64.0.0/10"
"fd7a:115c:a1e0::/96"
2024-05-25 13:47:17 +00:00
];
};
2024-05-22 20:57:56 +00:00
};
2023-08-07 19:38:01 +00:00
# settings = {
# schema_version = 20;
# bind_host = "127.0.0.1";
# bind_port = 3000;
#
# users = [
# {
# inherit (secret.adguardhome.users.daniel) name password;
# }
# ];
#
# auth_attempts = 3;
# debug_pprof = false;
#
# dns = {
# inherit (secret.adguardhome) bind_hosts;
# port = 53;
#
# bootstrap_dns = [
# "9.9.9.11"
# "149.112.112.11"
# "2620:fe::11"
# "2620:fe::fe:11"
# ];
# };
#
# tls = {
# enabled = false;
# allow_unencrypted_doh = true;
# };
#
# dhcp.enabled = false;
# };
2023-05-15 20:11:58 +00:00
};
2024-05-22 20:57:56 +00:00
systemd.services.adguardhome.serviceConfig = {
SupplementaryGroups = [ "nginx" ];
};
2023-06-07 18:40:27 +00:00
networking.firewall.interfaces =
let
2023-09-22 21:59:48 +00:00
interfaces = lib.mapAttrsToList (_: lib.attrsets.attrByPath [ "matchConfig" "Name" ] null) config.systemd.network.networks ++ [ "tailscale0" ];
2023-06-07 18:40:27 +00:00
in
builtins.listToAttrs
(builtins.map
(iface:
{
name = iface;
value = {
2024-05-22 20:57:56 +00:00
allowedTCPPorts = [ 53 1053 9053 10443 ];
allowedUDPPorts = [ 53 1053 9053 10443 ];
2023-06-07 18:40:27 +00:00
};
})
(builtins.filter builtins.isString interfaces));
2023-06-10 18:48:07 +00:00
virtualisation.podman.defaultNetwork.settings.dns_enabled = lib.mkForce secret.adguardhome.podmanDNS;
2024-05-22 08:48:16 +00:00
services.nginx = {
upstreams.adguardhome = {
servers = {
"127.0.0.1:3000" = {
fail_timeout = "2s";
};
};
extraConfig = ''
keepalive 16;
'';
};
virtualHosts."${secret.adguardhome.domain_prefix}.internal.kempkens.network" = {
2024-05-22 20:57:56 +00:00
serverAliases = [
"${secret.adguardhome.domain_prefix}-direct.internal.kempkens.network"
"dns.internal.kempkens.network"
];
2024-05-22 08:48:16 +00:00
listen = [
{
addr = "0.0.0.0";
port = 443;
ssl = true;
}
{
addr = "[::0]";
port = 443;
ssl = true;
}
{
addr = "0.0.0.0";
port = 9053;
ssl = true;
extraParameters = [
"fastopen=63"
"backlog=1023"
"deferred"
];
}
{
addr = "[::0]";
port = 9053;
ssl = true;
extraParameters = [
"fastopen=63"
"backlog=1023"
"deferred"
];
}
];
quic = true;
http3 = true;
onlySSL = true;
useACMEHost = "internal.kempkens.network";
extraConfig = ''
2024-07-18 21:07:07 +00:00
set_real_ip_from 100.122.253.109/32;
set_real_ip_from fd7a:115c:a1e0::3a01:fd6d/128;
2024-05-22 08:48:16 +00:00
real_ip_header X-Forwarded-For;
'';
locations."/" = {
recommendedProxySettings = true;
proxyPass = "http://adguardhome";
};
2023-05-15 20:11:58 +00:00
};
};
}