Trying to structure this to be a flake input.

This commit is contained in:
Yaro Kasear 2025-07-20 11:27:26 -05:00
parent 9b4bd81df3
commit 2e6fbe5856
3 changed files with 89 additions and 0 deletions

45
lib/metanix.nix Normal file
View file

@ -0,0 +1,45 @@
# lib/metanix.nix
{ data, lib }:
let
buildSystemIndex =
let
flattenSystems = locationName: subnetName: systems:
lib.mapAttrsToList
(systemName: systemCfg: {
inherit systemName locationName subnetName;
primary = systemCfg.primary or false;
macs = systemCfg.macAddresses or [ ];
})
systems;
allSystems =
builtins.concatLists (
lib.mapAttrsToList
(locationName: location:
builtins.concatLists (
lib.mapAttrsToList
(subnetName: subnet:
flattenSystems locationName subnetName (subnet.systems or { })
)
(location.subnets or { })
)
)
data.locations
);
in
builtins.foldl'
(acc: entry:
let
existing = acc.${entry.systemName} or [ ];
in
acc // {
${entry.systemName} = existing ++ [ builtins.removeAttrs entry [ "systemName" ] ];
}
)
{ }
allSystems;
in
{
inherit buildSystemIndex;
}