Starting out simple. Small.
This commit is contained in:
parent
cde6ba8905
commit
96cc5e9501
5 changed files with 47 additions and 62 deletions
|
|
@ -1,45 +1,12 @@
|
|||
# lib/metanix.nix
|
||||
{ data, lib }:
|
||||
|
||||
let
|
||||
buildSystemIndex =
|
||||
indexOf = name: names:
|
||||
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
|
||||
);
|
||||
indexed = builtins.imap0 (i: v: { inherit i v; }) names;
|
||||
matches = builtins.filter (x: x.v == name) indexed;
|
||||
in
|
||||
builtins.foldl'
|
||||
(acc: entry:
|
||||
let
|
||||
existing = acc.${entry.systemName} or [ ];
|
||||
in
|
||||
acc // {
|
||||
${entry.systemName} = existing ++ [ builtins.removeAttrs entry [ "systemName" ] ];
|
||||
}
|
||||
)
|
||||
{ }
|
||||
allSystems;
|
||||
if matches == [ ] then null else (builtins.head matches).i;
|
||||
|
||||
in
|
||||
{
|
||||
inherit buildSystemIndex;
|
||||
}
|
||||
{ indexOf = indexOf; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue