refactor(dns/network): replace dnsResolvableName
with hostname
and restructure DNS record generation
- Replaced `dnsResolvableName` with `hostname` in device configuration options - Updated DNS record generation logic to use `hostname` instead of domain-based naming - Removed deprecated `dnsResolvableName` option from network module - Restructured DNS record templates to use consistent formatting - Simplified code structure by removing redundant whitespace and reorganizing attribute definitions - Updated `generateDeviceHostRecords` to use new naming convention and improved template syntax
This commit is contained in:
parent
0e513e1c69
commit
184f039e40
@ -122,29 +122,31 @@ in
|
|||||||
generateDeviceHostRecords =
|
generateDeviceHostRecords =
|
||||||
let
|
let
|
||||||
generateRecordsForInterface = ifaceName: ifaceConfig:
|
generateRecordsForInterface = ifaceName: ifaceConfig:
|
||||||
lib.concatStringsSep "\n" (lib.mapAttrsToList (deviceName: deviceConfig:
|
lib.concatStringsSep "\n" (lib.mapAttrsToList
|
||||||
if deviceConfig.dnsResolvableName != null then
|
(deviceName: deviceConfig:
|
||||||
let
|
if deviceConfig.hostname!= null then
|
||||||
serverIP = deviceConfig.address;
|
let
|
||||||
interfaceNet = ifaceConfig.net;
|
deviceAddress = deviceConfig.address;
|
||||||
domain = deviceConfig.dnsResolvableName;
|
deviceIface = ifaceConfig.net;
|
||||||
in
|
deviceHost = deviceConfig.hostname;
|
||||||
''
|
in
|
||||||
${domain} {
|
''
|
||||||
view ${ifaceName} {
|
${deviceHost} {
|
||||||
expr incidr(client_ip(), '${interfaceNet}')
|
view ${ifaceName} {
|
||||||
}
|
expr incidr(client_ip(), '${deviceIface}')
|
||||||
|
}
|
||||||
|
|
||||||
template IN A ${domain} {
|
template IN A ${deviceHost} {
|
||||||
answer "${domain}. 60 IN A ${serverIP}"
|
answer "${deviceHost}. 60 IN A ${deviceAddress}"
|
||||||
}
|
}
|
||||||
|
|
||||||
cache
|
cache
|
||||||
log
|
log
|
||||||
}
|
}
|
||||||
''
|
''
|
||||||
else ""
|
else ""
|
||||||
) ifaceConfig.devices);
|
)
|
||||||
|
ifaceConfig.devices);
|
||||||
in
|
in
|
||||||
lib.concatStringsSep "\n" (lib.mapAttrsToList generateRecordsForInterface config.pepe.core.network.interfaces);
|
lib.concatStringsSep "\n" (lib.mapAttrsToList generateRecordsForInterface config.pepe.core.network.interfaces);
|
||||||
in
|
in
|
||||||
|
@ -36,18 +36,12 @@ in
|
|||||||
type = types.str;
|
type = types.str;
|
||||||
description = "The hostname of the device.";
|
description = "The hostname of the device.";
|
||||||
};
|
};
|
||||||
|
|
||||||
isEndpoint = mkOption {
|
isEndpoint = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = "Whether this device serves as a DNS endpoint for this interface.";
|
description = "Whether this device serves as a DNS endpoint for this interface.";
|
||||||
};
|
};
|
||||||
|
|
||||||
dnsResolvableName = mkOption {
|
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
description = "The fully qualified domain name that should resolve to this device's IP address. e.g., my-device.lan.example.com";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
default = { };
|
default = { };
|
||||||
@ -58,14 +52,14 @@ in
|
|||||||
default = { };
|
default = { };
|
||||||
description = "An attribute set of networks with their configurations.";
|
description = "An attribute set of networks with their configurations.";
|
||||||
};
|
};
|
||||||
|
|
||||||
interfacesByType = mkOption {
|
interfacesByType = mkOption {
|
||||||
type = types.attrsOf (types.listOf types.str);
|
type = types.attrsOf (types.listOf types.str);
|
||||||
default = {};
|
default = { };
|
||||||
description = "Interfaces grouped by type (lan, wan, vpn) for easy access.";
|
description = "Interfaces grouped by type (lan, wan, vpn) for easy access.";
|
||||||
internal = true;
|
internal = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
dnsEndpoints = mkOption {
|
dnsEndpoints = mkOption {
|
||||||
type = types.attrsOf (types.submodule {
|
type = types.attrsOf (types.submodule {
|
||||||
options = {
|
options = {
|
||||||
@ -73,17 +67,17 @@ in
|
|||||||
type = types.str;
|
type = types.str;
|
||||||
description = "The interface this DNS endpoint belongs to.";
|
description = "The interface this DNS endpoint belongs to.";
|
||||||
};
|
};
|
||||||
|
|
||||||
device = mkOption {
|
device = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "The device name that serves as the DNS endpoint.";
|
description = "The device name that serves as the DNS endpoint.";
|
||||||
};
|
};
|
||||||
|
|
||||||
address = mkOption {
|
address = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "The IP address of the DNS endpoint.";
|
description = "The IP address of the DNS endpoint.";
|
||||||
};
|
};
|
||||||
|
|
||||||
serverName = mkOption {
|
serverName = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = "";
|
default = "";
|
||||||
@ -91,12 +85,12 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
default = {};
|
default = { };
|
||||||
description = "DNS endpoints for each interface.";
|
description = "DNS endpoints for each interface.";
|
||||||
internal = true;
|
internal = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
# Create lists of interfaces by type for easy access elsewhere
|
# Create lists of interfaces by type for easy access elsewhere
|
||||||
pepe.core.network.interfacesByType = {
|
pepe.core.network.interfacesByType = {
|
||||||
@ -104,15 +98,15 @@ in
|
|||||||
wan = lib.attrNames (lib.filterAttrs (_: iface: iface.type == "wan") cfg.interfaces);
|
wan = lib.attrNames (lib.filterAttrs (_: iface: iface.type == "wan") cfg.interfaces);
|
||||||
vpn = lib.attrNames (lib.filterAttrs (_: iface: iface.type == "vpn") cfg.interfaces);
|
vpn = lib.attrNames (lib.filterAttrs (_: iface: iface.type == "vpn") cfg.interfaces);
|
||||||
};
|
};
|
||||||
|
|
||||||
# Collect DNS endpoints from all interfaces
|
# Collect DNS endpoints from all interfaces
|
||||||
pepe.core.network.dnsEndpoints =
|
pepe.core.network.dnsEndpoints =
|
||||||
let
|
let
|
||||||
collectEndpoints = ifaceName: iface:
|
collectEndpoints = ifaceName: iface:
|
||||||
lib.mapAttrs'
|
lib.mapAttrs'
|
||||||
(deviceName: device:
|
(deviceName: device:
|
||||||
lib.nameValuePair
|
lib.nameValuePair
|
||||||
"${ifaceName}-${deviceName}"
|
"${ifaceName}-${deviceName}"
|
||||||
{
|
{
|
||||||
interface = ifaceName;
|
interface = ifaceName;
|
||||||
device = deviceName;
|
device = deviceName;
|
||||||
@ -122,11 +116,11 @@ in
|
|||||||
)
|
)
|
||||||
(lib.filterAttrs (_: device: device.isDnsEndpoint) iface.devices);
|
(lib.filterAttrs (_: device: device.isDnsEndpoint) iface.devices);
|
||||||
in
|
in
|
||||||
lib.foldl
|
lib.foldl
|
||||||
(acc: ifaceName:
|
(acc: ifaceName:
|
||||||
acc // (collectEndpoints ifaceName cfg.interfaces.${ifaceName})
|
acc // (collectEndpoints ifaceName cfg.interfaces.${ifaceName})
|
||||||
)
|
)
|
||||||
{}
|
{ }
|
||||||
(lib.attrNames cfg.interfaces);
|
(lib.attrNames cfg.interfaces);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user