diff --git a/meta/nodes/liminix.nix b/meta/nodes/liminix.nix index 3510908..8f654a2 100644 --- a/meta/nodes/liminix.nix +++ b/meta/nodes/liminix.nix @@ -14,12 +14,11 @@ # deployment = {}; # Colmena deployment options # nixpkgs = "unstable" or "22.11"; # nixpkgs version # } - let - lib = import ../../lib/nix-lib; - inherit (lib) mapFuse; + nix-lib = import ../../lib/nix-lib; + inherit (nix-lib) mapFuse; - mkAP = building: floor: ap-no: { + mkAP' = building: floor: ap-no: { "ap-v01-${builtins.toString building}-${builtins.toString floor}-${builtins.toString ap-no}" = { site = "unknown"; adminGroups = [ "fai" ]; @@ -39,37 +38,53 @@ let }; }; }; + + /* + Generate all APs nodes for a building. It takes a building definition and returns + an attributes set containing all nodes of the AP for the building. + + Building definition: + * building-no is the index of the building + * floors is the range {from, to{ of floors that contains an AP + * ap-nos is the range [from, to{ of AP numbers + + Type: AttrSet -> AttrSet + */ + mkAPs-building = + { + building-no, + floors, + ap-nos, + }: + mapFuse (f: mapFuse (mkAP' building-no f) (mkRange ap-nos)) (mkRange floors); + + APs = { + hypnos-1 = { + building-no = 0; + floors = { + from = 0; + to = 3; + }; + ap-nos = { + from = 1; + to = 7; + }; + }; + + hypnos-2 = { + building-no = 1; + floors = { + from = 0; + to = 3; + }; + ap-nos = { + from = 1; + to = 3; + }; + }; + }; + + mkRange = { from, to }: builtins.genList (x: x + from) (to - from); in { } -// - mapFuse - ( - floor: - mapFuse (mkAP 0 floor) [ - 1 - 2 - 3 - 4 - 5 - 6 - ] - ) - [ - 0 - 1 - 2 - ] # Hypnos-1 -// - mapFuse - ( - floor: - mapFuse (mkAP 1 floor) [ - 1 - 2 - ] - ) - [ - 0 - 1 - 2 - ] # Hypnos-2 +// builtins.foldl' (nodes: building: nodes // mkAPs-building building) { } (builtins.attrValues APs)