33 lines
816 B
Nix
33 lines
816 B
Nix
{lib, machineDir, ... }:
|
|
let
|
|
|
|
allMachineNames =
|
|
let
|
|
#machineDir = "${config.clanCore.clanDir}/machines/";
|
|
#machineDir = ../../machines;
|
|
machines = lib.mapAttrsToList (name: _: name) (builtins.readDir machineDir);
|
|
in
|
|
machines;
|
|
|
|
getFactPath = fact: machine:
|
|
"${machineDir}/${machine}/facts/${fact}";
|
|
|
|
readFact = fact: machine:
|
|
let
|
|
path = getFactPath fact machine;
|
|
in
|
|
if builtins.pathExists path then
|
|
builtins.readFile path
|
|
else
|
|
null;
|
|
|
|
readFactFromAllMachines = fact:
|
|
let
|
|
machines = allMachineNames;
|
|
facts = lib.genAttrs machines (readFact fact);
|
|
filteredFacts = lib.filterAttrs (_machine: fact: fact != null) facts;
|
|
in
|
|
filteredFacts;
|
|
|
|
in
|
|
{ inherit allMachineNames getFactPath readFact readFactFromAllMachines; }
|