nixos/hosts/architect/dns.nix

106 lines
2.5 KiB
Nix
Raw Normal View History

2024-01-30 23:20:07 +00:00
{ config, lib, ... }:
2021-08-23 19:00:19 +01:00
with lib;
2023-02-11 02:29:48 +00:00
let
generateCoreDNSConfig = domains:
2024-01-30 23:20:07 +00:00
let
generateForDomain = domain: conf:
concatMapStrings
(iface:
let
architectIP = config.architect.networks.${iface}.devices.architect.address;
interfaceNet = config.architect.networks.${iface}.net;
in
''
${domain} {
view ${iface} {
expr incidr(client_ip(), '${interfaceNet}')
}
2024-01-30 23:20:07 +00:00
template IN A ${domain} {
answer "${domain}. 60 IN A ${architectIP}"
}
template IN HTTPS ${domain} {
answer "${domain}. 60 IN HTTPS 1 . ipv4hint=\"${architectIP}\""
}
cache
log
2024-01-30 23:20:07 +00:00
}
''
)
conf.dnsInterfaces;
2024-01-30 23:20:07 +00:00
in
concatStrings (mapAttrsToList generateForDomain domains);
# Combine vhosts and the single domain
allDomains = config.architect.vhost // {
"architect.devs.giugl.io" = { dnsInterfaces = [ "lan" "tailscale" ]; };
};
domain = "adguard.giugl.io";
2022-07-06 19:34:12 +01:00
in
2021-08-23 19:00:19 +01:00
{
architect.vhost.${domain} = with config.architect.networks; {
dnsInterfaces = [ "tailscale" "lan" ];
locations."/" = {
port = config.services.adguardhome.port;
allowLan = true;
allow = [
tailscale.net
];
};
};
2023-06-04 23:30:07 +01:00
services = {
2024-01-30 23:20:07 +00:00
coredns = {
2021-08-23 19:01:35 +01:00
enable = true;
2024-01-30 23:20:07 +00:00
config = ''
${generateCoreDNSConfig allDomains}
2024-01-30 23:20:07 +00:00
. {
cache
forward . 127.0.0.1:${toString config.services.adguardhome.settings.dns.port}
}
'';
2021-08-23 19:00:19 +01:00
};
2021-09-25 17:22:18 +01:00
adguardhome = {
2021-11-25 11:42:32 +00:00
enable = true;
2023-05-28 21:45:49 +01:00
settings = {
2024-06-01 11:41:26 +01:00
port = 5354;
2023-05-28 21:45:49 +01:00
dns = {
port = 5300;
};
upstream_dns = [
"tls://architect.d65174.dns.nextdns.io"
"https://dns.nextdns.io/d65174/architect"
];
};
2021-08-23 19:00:19 +01:00
};
2023-06-27 04:15:39 +01:00
dnscrypt-proxy2 = {
enable = true;
settings = {
listen_addresses = [ "127.0.0.1:5354" ];
2023-06-27 04:15:39 +01:00
ipv4_servers = true;
ipv6_servers = false;
block_ipv6 = true;
dnscrypt_servers = true;
doh_servers = true;
require_nolog = true;
require_nofilter = true;
timeout = 350;
lb_strategy = "p4";
lb_estimator = true;
ignore_system_dns = true;
fallback_resolvers = [ "1.1.1.1:53" "9.9.9.9:53" ];
cache_min_ttl = 60;
cache_max_ttl = 360;
};
};
2021-08-23 19:01:35 +01:00
};
2021-08-23 19:00:19 +01:00
}