Trying to structure this to be a flake input.
This commit is contained in:
parent
9b4bd81df3
commit
2e6fbe5856
3 changed files with 89 additions and 0 deletions
45
lib/metanix.nix
Normal file
45
lib/metanix.nix
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue