From 05c45371af734eb507e2904df763f53005b4efbc Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 9 Apr 2025 17:28:17 +0200 Subject: [PATCH] feat(buildInventory): move instance resolution into buildInventory Such that buildClan doesn't have to compose the results buildInventory should be more self contained. But it is NOT meant a public API! use buildClan argument 'inventory' instead --- lib/build-clan/interface.nix | 2 -- lib/build-clan/module.nix | 20 +++++++++---------- .../build-inventory/builder/interface.nix | 3 +++ lib/inventory/build-inventory/default.nix | 19 +++++++++++++++++- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/lib/build-clan/interface.nix b/lib/build-clan/interface.nix index 63db32f2d..5b38735f3 100644 --- a/lib/build-clan/interface.nix +++ b/lib/build-clan/interface.nix @@ -162,8 +162,6 @@ in inventoryFile = lib.mkOption { type = lib.types.raw; }; # The machine 'imports' generated by the inventory per machine inventoryClass = lib.mkOption { type = lib.types.raw; }; - # new attribute - distributedServices = lib.mkOption { type = lib.types.raw; }; # clan-core's modules clanModules = lib.mkOption { type = lib.types.raw; }; source = lib.mkOption { type = lib.types.raw; }; diff --git a/lib/build-clan/module.nix b/lib/build-clan/module.nix index 9e28fee75..44d8b5883 100644 --- a/lib/build-clan/module.nix +++ b/lib/build-clan/module.nix @@ -46,6 +46,7 @@ let inventoryClass = ( buildInventory { inherit inventory directory; + flakeInputs = config.self.inputs; } ); @@ -76,19 +77,16 @@ let clan-core.nixosModules.clanCore extraConfig (machines.${name} or { }) - # Inherit the inventory assertions ? - # { inherit (mergedInventory) assertions; } + { imports = inventoryClass.machines.${name}.machineImports or [ ]; } - # Import the distribute services - { imports = config.clanInternals.distributedServices.allMachines.${name} or [ ]; } ( { # Settings clan.core.settings = { - inherit directory; inherit (config.inventory.meta) name icon; + inherit directory; machine = { inherit name; }; @@ -254,12 +252,14 @@ in inherit darwinConfigurations; clanInternals = { - moduleSchemas = clan-core.clanLib.modules.getModulesSchema config.inventory.modules; - inherit inventoryClass; - distributedServices = clan-core.clanLib.inventory.mapInstances { - inherit inventory; - flakeInputs = config.self.inputs; + moduleSchemas = clan-core.clanLib.modules.getModulesSchema { + modules = config.inventory.modules; + # TODO: make this function system agnostic + pkgs = nixpkgs.legacyPackages."x86_64-linux"; + inherit clan-core; }; + inherit inventoryClass; + # TODO: unify this interface # We should have only clan.modules. (consistent with clan.templates) inherit (clan-core) clanModules clanLib; diff --git a/lib/inventory/build-inventory/builder/interface.nix b/lib/inventory/build-inventory/builder/interface.nix index 90f161865..cc681065c 100644 --- a/lib/inventory/build-inventory/builder/interface.nix +++ b/lib/inventory/build-inventory/builder/interface.nix @@ -9,6 +9,9 @@ in directory = mkOption { type = types.path; }; + distributedServices = mkOption { + type = types.raw; + }; inventory = mkOption { type = types.raw; }; diff --git a/lib/inventory/build-inventory/default.nix b/lib/inventory/build-inventory/default.nix index c11176305..2b069e3ad 100644 --- a/lib/inventory/build-inventory/default.nix +++ b/lib/inventory/build-inventory/default.nix @@ -8,7 +8,11 @@ let machinesFromInventory :: Inventory -> { ${machine_name} :: NixOSConfiguration } */ buildInventory = - { inventory, directory }: + { + inventory, + directory, + flakeInputs, + }: (lib.evalModules { specialArgs = { inherit clanLib; @@ -16,6 +20,19 @@ let modules = [ ./builder { inherit directory inventory; } + ( + # config.distributedServices.allMachines.${name} or [ ]; + { config, ... }: + { + distributedServices = clanLib.inventory.mapInstances { + inherit (config) inventory; + inherit flakeInputs; + }; + machines = lib.mapAttrs (machineName: v: { + machineImports = v; + }) config.distributedServices.allMachines; + } + ) ]; }).config; in