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:
Giulio De Pasquale 2025-06-05 16:53:35 +01:00
parent 0e513e1c69
commit 184f039e40
2 changed files with 42 additions and 46 deletions

View File

@ -122,21 +122,22 @@ 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:
if deviceConfig.hostname!= null then
let let
serverIP = deviceConfig.address; deviceAddress = deviceConfig.address;
interfaceNet = ifaceConfig.net; deviceIface = ifaceConfig.net;
domain = deviceConfig.dnsResolvableName; deviceHost = deviceConfig.hostname;
in in
'' ''
${domain} { ${deviceHost} {
view ${ifaceName} { view ${ifaceName} {
expr incidr(client_ip(), '${interfaceNet}') 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
@ -144,7 +145,8 @@ in
} }
'' ''
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

View File

@ -42,12 +42,6 @@ in
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 = { };