diff --git a/lib/build-clan/module.nix b/lib/build-clan/module.nix index 301b57d85..60865b5e1 100644 --- a/lib/build-clan/module.nix +++ b/lib/build-clan/module.nix @@ -45,6 +45,7 @@ let inherit inventory directory; flakeInputs = config.self.inputs; prefix = config._prefix ++ [ "inventoryClass" ]; + localModuleSet = config.self.clan.modules; } ); diff --git a/lib/inventory/build-inventory/default.nix b/lib/inventory/build-inventory/default.nix index 33de3902f..bfb3705f0 100644 --- a/lib/inventory/build-inventory/default.nix +++ b/lib/inventory/build-inventory/default.nix @@ -13,6 +13,7 @@ let directory, flakeInputs, prefix ? [ ], + localModuleSet ? { }, }: (lib.evalModules { # TODO: remove clanLib from specialArgs @@ -21,6 +22,9 @@ let }; modules = [ ./builder + (lib.modules.importApply ./service-list-from-inputs.nix { + inherit flakeInputs clanLib localModuleSet; + }) { inherit directory inventory; } ( # config.distributedServices.allMachines.${name} or [ ]; diff --git a/lib/inventory/build-inventory/service-list-from-inputs.nix b/lib/inventory/build-inventory/service-list-from-inputs.nix new file mode 100644 index 000000000..07659cc67 --- /dev/null +++ b/lib/inventory/build-inventory/service-list-from-inputs.nix @@ -0,0 +1,43 @@ +{ + flakeInputs, + clanLib, + localModuleSet, +}: +{ lib, config, ... }: + +let + + inspectModule = + inputName: moduleName: module: + let + eval = clanLib.inventory.evalClanService { + modules = [ module ]; + prefix = [ + inputName + "clan" + "modules" + moduleName + ]; + }; + in + { + manifest = eval.config.manifest; + roles = lib.mapAttrs (_n: _v: { }) eval.config.roles; + }; +in +{ + options.modulesPerSource = lib.mkOption { + # { sourceName :: { moduleName :: {} }} + default = + let + inputsWithModules = lib.filterAttrs (_inputName: v: v ? clan.modules) flakeInputs; + + in + lib.mapAttrs ( + inputName: v: lib.mapAttrs (inspectModule inputName) v.clan.modules + ) inputsWithModules; + }; + options.localModules = lib.mkOption { + default = lib.mapAttrs (inspectModule "self") localModuleSet; + }; +}