45 lines
1.1 KiB
Nix
45 lines
1.1 KiB
Nix
# 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;
|
|
}
|