From 9024590a347c58d4ccb15cf3a6eee81e06e575c0 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Mon, 9 Dec 2024 11:27:10 +0100 Subject: [PATCH] fix(netconf/dgn-hardware): Some models are extension cards --- modules/netconf/dgn-hardware/default.nix | 44 ++++++++++++++++-------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/modules/netconf/dgn-hardware/default.nix b/modules/netconf/dgn-hardware/default.nix index f376ee9..e49c062 100644 --- a/modules/netconf/dgn-hardware/default.nix +++ b/modules/netconf/dgn-hardware/default.nix @@ -3,7 +3,7 @@ let inherit (lib) genList mkOption listToAttrs; - inherit (lib.types) enum; + inherit (lib.types) enum listOf; range = prefix: genList (port: "${prefix}${builtins.toString port}"); mkInterfaces = @@ -17,6 +17,24 @@ let }) interfaces ); + mkAllInterfaces = builtins.foldl' ( + interfaces: model: + interfaces + // ( + let + ports = import ./. + "${model}.nix" range; + in + (mkInterfaces { + supportPoE = true; + interfaces = ports.poe; + }) + // (mkInterfaces { + supportPoE = false; + interfaces = ports.regular; + }) + ) + ) { }; + cfg = config.dgn-hardware; in @@ -27,26 +45,24 @@ in "EX2300-48P" "EX4100-F-48P" "EX4400-24X" - "EX4400-EM-4Y" ]; description = '' The exact model of the switch to configure. ''; }; + + extensions = mkOption { + type = listOf (enum [ + "EX4400-EM-4Y" + ]); + default = [ ]; + description = '' + List of hardware extensions included in the switch. + ''; + }; }; config = { - netconf.mandatoryInterfaces = - let - ports = import ./. + "${cfg.model}.nix" range; - in - (mkInterfaces { - supportPoE = true; - interfaces = ports.poe; - }) - // (mkInterfaces { - supportPoE = false; - interfaces = ports.regular; - }); + netconf.mandatoryInterfaces = mkAllInterfaces ([ cfg.model ] ++ cfg.extensions); }; }