From 9c2bf0bbfe4371163ed16ebfc4cfc3e216c6315d Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Tue, 3 Jun 2025 17:36:03 +0200 Subject: [PATCH] feat(inventory/instances): map over all machines and return lazy attributes --- lib/inventory/build-inventory/default.nix | 5 +---- .../distributed-service/inventory-adapter.nix | 17 ++++++++--------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/inventory/build-inventory/default.nix b/lib/inventory/build-inventory/default.nix index 8e3cb45ca..0e67452f4 100644 --- a/lib/inventory/build-inventory/default.nix +++ b/lib/inventory/build-inventory/default.nix @@ -30,16 +30,13 @@ let # config.distributedServices.allMachines.${name} or [ ]; { config, ... }: { - distributedServices = clanLib.inventory.mapInstances { inherit (config) inventory; inherit localModuleSet; inherit flakeInputs; prefix = prefix ++ [ "distributedServices" ]; }; - machines = lib.mapAttrs (_machineName: v: { - machineImports = v; - }) config.distributedServices.allMachines; + machines = config.distributedServices.allMachines; } ) diff --git a/lib/inventory/distributed-service/inventory-adapter.nix b/lib/inventory/distributed-service/inventory-adapter.nix index b2fa2de35..e3a90d440 100644 --- a/lib/inventory/distributed-service/inventory-adapter.nix +++ b/lib/inventory/distributed-service/inventory-adapter.nix @@ -157,6 +157,7 @@ in modules = [ # Import the resolved module. + # i.e. clan.modules.admin (builtins.head instances).instance.resolvedModule ] # Include all the instances that correlate to the resolved module ++ (builtins.map (v: { @@ -185,20 +186,18 @@ in } ) { } importedModuleWithInstances; - # TODO: Return an attribute set of resources instead of a plain list of nixosModules - allMachines = lib.foldlAttrs ( - acc: _module_ident: eval: - acc - // lib.mapAttrs ( - machineName: result: acc.${machineName} or [ ] ++ [ result.nixosModule ] - ) eval.config.result.final - ) { } importedModulesEvaluated; + allMachines = lib.mapAttrs (machineName: _: { + # This is the list of nixosModules for each machine + machineImports = lib.foldlAttrs ( + acc: _module_ident: eval: + acc ++ [ eval.config.result.final.${machineName}.nixosModule or {}] + ) [ ] importedModulesEvaluated; + }) inventory.machines; in { inherit importedModuleWithInstances grouped - allMachines importedModulesEvaluated ;