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

73 lines
1.5 KiB
Nix

# SPDX-FileCopyrightText: 2024 Lubin Bailly <lubin.bailly@dgnum.eu>
# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
#
# SPDX-License-Identifier: EUPL-1.2
{ config, lib, ... }:
let
inherit (lib) genList mkOption listToAttrs;
inherit (lib.types) enum listOf;
range = prefix: genList (port: "${prefix}${builtins.toString port}");
mkInterfaces =
{ supportPoE, interfaces }:
listToAttrs (
builtins.map (int: {
name = int;
value = {
inherit supportPoE;
};
}) 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
{
options.dgn-hardware = {
model = mkOption {
type = enum [
"EX2300-48P"
"EX4100-F-48P"
"EX4400-24X"
];
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 = mkAllInterfaces ([ cfg.model ] ++ cfg.extensions);
};
}