1
1
Fork 1
mirror of https://github.com/oddlama/nix-config.git synced 2025-10-10 23:00:39 +02:00

feat(topology): add kea network extractor

This commit is contained in:
oddlama 2024-04-01 15:15:31 +02:00
parent 0013dd2d01
commit 1d207e0fd2
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A

View file

@ -0,0 +1,34 @@
{
config,
lib,
...
}: let
inherit
(lib)
const
filter
genAttrs
hasInfix
mkEnableOption
mkIf
;
in {
options.topology.extractors.kea.enable = mkEnableOption "topology kea extractor" // {default = true;};
config = let
interfaces = filter (x: !hasInfix "*" x) config.services.kea.dhcp4.settings.interfaces-config.interfaces or [];
headOrNull = xs:
if xs == []
then null
else builtins.head xs;
subnet = headOrNull (map (x: x.subnet) (config.services.kea.dhcp4.settings.subnet4 or []));
netName = "${config.topology.self.id}-kea";
in
mkIf (config.topology.extractors.kea.enable && config.services.kea.dhcp4.enable && interfaces != [] && subnet != null) {
topology.networks.${netName} = {
cidrv4 = subnet;
};
topology.self.interfaces = genAttrs interfaces (const {network = netName;});
};
}