refactor: simplify DNS configuration generation and remove processDomainsFirst option
This commit is contained in:
parent
c1baa0eb65
commit
3508ebc879
@ -18,23 +18,17 @@ in
|
||||
description = "NextDNS ID for DNS over TLS.";
|
||||
};
|
||||
|
||||
processDomainsFirst = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Process all domains first, then add device views just once.";
|
||||
};
|
||||
|
||||
extraDomains = mkOption {
|
||||
type = types.attrsOf (types.submodule {
|
||||
options = {
|
||||
dnsInterfaces = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [];
|
||||
default = [ ];
|
||||
description = "List of interfaces to add DNS entries for this domain.";
|
||||
};
|
||||
};
|
||||
});
|
||||
default = {};
|
||||
default = { };
|
||||
description = "Additional domains to add to DNS configuration.";
|
||||
};
|
||||
};
|
||||
@ -42,7 +36,8 @@ in
|
||||
config = mkIf cfg.enable {
|
||||
services.coredns = {
|
||||
enable = true;
|
||||
config = let
|
||||
config =
|
||||
let
|
||||
# Function to generate domain-specific configurations
|
||||
generateDomainConfig = domain: conf: ifaceName:
|
||||
let
|
||||
@ -105,39 +100,21 @@ in
|
||||
));
|
||||
|
||||
# Generate all device views once
|
||||
allDeviceViews = if cfg.processDomainsFirst
|
||||
then concatMapStrings generateDeviceViews allInterfaces
|
||||
else "";
|
||||
allDeviceViews = concatMapStrings generateDeviceViews allInterfaces;
|
||||
|
||||
# Function to generate configurations for all domains
|
||||
generateCoreDNSConfig = domains:
|
||||
let
|
||||
generateForDomain = domain: conf:
|
||||
if cfg.processDomainsFirst then
|
||||
# Just generate domain configs without device views
|
||||
concatMapStrings
|
||||
(ifaceName: generateDomainConfig domain conf ifaceName)
|
||||
conf.dnsInterfaces
|
||||
else
|
||||
# Original behavior: interleave domains and device views
|
||||
concatMapStrings
|
||||
(ifaceName:
|
||||
let
|
||||
domainConfig = generateDomainConfig domain conf ifaceName;
|
||||
deviceViews = generateDeviceViews ifaceName;
|
||||
in
|
||||
''
|
||||
${domainConfig}
|
||||
|
||||
${deviceViews}
|
||||
''
|
||||
)
|
||||
conf.dnsInterfaces;
|
||||
in
|
||||
concatStrings (mapAttrsToList generateForDomain domains);
|
||||
|
||||
allDomains = config.pepe.core.vhost.hosts // cfg.extraDomains;
|
||||
in ''
|
||||
in
|
||||
''
|
||||
${generateCoreDNSConfig allDomains}
|
||||
|
||||
${allDeviceViews}
|
||||
|
Loading…
x
Reference in New Issue
Block a user