Starting out simple. Small.

This commit is contained in:
Yaro Kasear 2025-07-20 12:45:51 -05:00
parent cde6ba8905
commit 96cc5e9501
5 changed files with 47 additions and 62 deletions

View file

@ -0,0 +1 @@
locations: builtins.attrNames locations

View file

@ -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; }