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:
parent
0013dd2d01
commit
1d207e0fd2
1 changed files with 34 additions and 0 deletions
34
topology/nixos/extractors/kea.nix
Normal file
34
topology/nixos/extractors/kea.nix
Normal 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;});
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue