infrastructure/modules/netconf/dgn-hardware/default.nix

52 lines
993 B
Nix

{ config, lib, ... }:
let
inherit (lib) genList mkOption listToAttrs;
inherit (lib.types) enum;
range = prefix: genList (port: "${prefix}${builtins.toString port}");
mkInterfaces =
{ supportPoE, interfaces }:
listToAttrs (
builtins.map (int: {
name = int;
value = {
inherit supportPoE;
};
}) interfaces
);
cfg = config.dgn-hardware;
in
{
options.dgn-hardware = {
model = mkOption {
type = enum [
"EX2300-48P"
"EX4100-F-48P"
"EX4400-24X"
"EX4400-EM-4Y"
];
description = ''
The exact model of the switch to configure.
'';
};
};
config = {
netconf.mandatoryInterfaces =
let
ports = import ./. + "${cfg.model}.nix" range;
in
(mkInterfaces {
supportPoE = true;
interfaces = ports.poe;
})
// (mkInterfaces {
supportPoE = false;
interfaces = ports.regular;
});
};
}