refactor(dns): simplify DNS config and associate architect domain to every interface
This commit is contained in:
parent
e10d9a4d5a
commit
74efccbdb6
@ -1,43 +1,51 @@
|
|||||||
{ config, lib, ... }:
|
{ config, lib, ... }:
|
||||||
|
|
||||||
let
|
with lib;
|
||||||
# Function to generate CoreDNS config for a single vhost
|
|
||||||
generateCoreDNSConfigForVhost = domain: conf:
|
|
||||||
let
|
|
||||||
# Retrieve architect's IP on each interface
|
|
||||||
interfaceConfigs = builtins.map
|
|
||||||
(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}')
|
|
||||||
}
|
|
||||||
|
|
||||||
template IN A ${domain} {
|
let
|
||||||
answer "${domain}. 60 IN A ${architectIP}"
|
generateCoreDNSConfig = domains:
|
||||||
|
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}')
|
||||||
|
}
|
||||||
|
|
||||||
|
template IN A ${domain} {
|
||||||
|
answer "${domain}. 60 IN A ${architectIP}"
|
||||||
|
}
|
||||||
|
|
||||||
|
template IN HTTPS ${domain} {
|
||||||
|
answer "${domain}. 60 IN HTTPS 1 . ipv4hint=\"${architectIP}\""
|
||||||
|
}
|
||||||
|
|
||||||
|
cache
|
||||||
|
log
|
||||||
}
|
}
|
||||||
template IN HTTPS ${domain} {
|
''
|
||||||
answer "${domain}. 60 IN HTTPS 1 . ipv4hint=\"${architectIP}\""
|
)
|
||||||
}
|
conf.dnsInterfaces;
|
||||||
cache
|
|
||||||
log
|
|
||||||
}
|
|
||||||
''
|
|
||||||
)
|
|
||||||
conf.dnsInterfaces;
|
|
||||||
in
|
in
|
||||||
lib.concatStringsSep "\n" interfaceConfigs;
|
concatStrings (mapAttrsToList generateForDomain domains);
|
||||||
|
|
||||||
|
# Combine vhosts and the single domain
|
||||||
|
allDomains = config.architect.vhost // {
|
||||||
|
"architect.devs.giugl.io" = { dnsInterfaces = [ "lan" "tailscale" ]; };
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
services = {
|
services = {
|
||||||
coredns = {
|
coredns = {
|
||||||
enable = true;
|
enable = true;
|
||||||
config = ''
|
config = ''
|
||||||
${lib.concatStringsSep "\n" (lib.mapAttrsToList generateCoreDNSConfigForVhost config.architect.vhost)}
|
${generateCoreDNSConfig allDomains}
|
||||||
|
|
||||||
. {
|
. {
|
||||||
cache
|
cache
|
||||||
|
Loading…
Reference in New Issue
Block a user