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.";
|
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 {
|
extraDomains = mkOption {
|
||||||
type = types.attrsOf (types.submodule {
|
type = types.attrsOf (types.submodule {
|
||||||
options = {
|
options = {
|
||||||
dnsInterfaces = mkOption {
|
dnsInterfaces = mkOption {
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
default = [];
|
default = [ ];
|
||||||
description = "List of interfaces to add DNS entries for this domain.";
|
description = "List of interfaces to add DNS entries for this domain.";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
default = {};
|
default = { };
|
||||||
description = "Additional domains to add to DNS configuration.";
|
description = "Additional domains to add to DNS configuration.";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -42,7 +36,8 @@ in
|
|||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
services.coredns = {
|
services.coredns = {
|
||||||
enable = true;
|
enable = true;
|
||||||
config = let
|
config =
|
||||||
|
let
|
||||||
# Function to generate domain-specific configurations
|
# Function to generate domain-specific configurations
|
||||||
generateDomainConfig = domain: conf: ifaceName:
|
generateDomainConfig = domain: conf: ifaceName:
|
||||||
let
|
let
|
||||||
@ -105,39 +100,21 @@ in
|
|||||||
));
|
));
|
||||||
|
|
||||||
# Generate all device views once
|
# Generate all device views once
|
||||||
allDeviceViews = if cfg.processDomainsFirst
|
allDeviceViews = concatMapStrings generateDeviceViews allInterfaces;
|
||||||
then concatMapStrings generateDeviceViews allInterfaces
|
|
||||||
else "";
|
|
||||||
|
|
||||||
# Function to generate configurations for all domains
|
# Function to generate configurations for all domains
|
||||||
generateCoreDNSConfig = domains:
|
generateCoreDNSConfig = domains:
|
||||||
let
|
let
|
||||||
generateForDomain = domain: conf:
|
generateForDomain = domain: conf:
|
||||||
if cfg.processDomainsFirst then
|
|
||||||
# Just generate domain configs without device views
|
|
||||||
concatMapStrings
|
concatMapStrings
|
||||||
(ifaceName: generateDomainConfig domain conf ifaceName)
|
(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;
|
conf.dnsInterfaces;
|
||||||
in
|
in
|
||||||
concatStrings (mapAttrsToList generateForDomain domains);
|
concatStrings (mapAttrsToList generateForDomain domains);
|
||||||
|
|
||||||
allDomains = config.pepe.core.vhost.hosts // cfg.extraDomains;
|
allDomains = config.pepe.core.vhost.hosts // cfg.extraDomains;
|
||||||
in ''
|
in
|
||||||
|
''
|
||||||
${generateCoreDNSConfig allDomains}
|
${generateCoreDNSConfig allDomains}
|
||||||
|
|
||||||
${allDeviceViews}
|
${allDeviceViews}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user