From 843f55f8440dfb53adcf1f0faf39353f3946f7e4 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 22 Oct 2025 16:29:33 +0200 Subject: [PATCH 1/4] modules: simplify inventoryClass module --- modules/clan/module.nix | 2 +- modules/inventoryClass/builder/default.nix | 5 ----- .../inventoryClass/{builder/interface.nix => default.nix} | 1 - 3 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 modules/inventoryClass/builder/default.nix rename modules/inventoryClass/{builder/interface.nix => default.nix} (99%) diff --git a/modules/clan/module.nix b/modules/clan/module.nix index 66d762e87..d3db7cbf9 100644 --- a/modules/clan/module.nix +++ b/modules/clan/module.nix @@ -228,7 +228,7 @@ in inherit clanLib; }; imports = [ - ../inventoryClass/builder/default.nix + ../inventoryClass/default.nix (lib.modules.importApply ../inventoryClass/service-list-from-inputs.nix { inherit flakeInputs clanLib; }) diff --git a/modules/inventoryClass/builder/default.nix b/modules/inventoryClass/builder/default.nix deleted file mode 100644 index bd4ca0b59..000000000 --- a/modules/inventoryClass/builder/default.nix +++ /dev/null @@ -1,5 +0,0 @@ -{ - imports = [ - ./interface.nix - ]; -} diff --git a/modules/inventoryClass/builder/interface.nix b/modules/inventoryClass/default.nix similarity index 99% rename from modules/inventoryClass/builder/interface.nix rename to modules/inventoryClass/default.nix index 217e139fd..0a95378ec 100644 --- a/modules/inventoryClass/builder/interface.nix +++ b/modules/inventoryClass/default.nix @@ -2,7 +2,6 @@ let inherit (lib) types mkOption; submodule = m: types.submoduleWith { modules = [ m ]; }; - in { options = { From a25d983c87757a8c81f16d81bcec7fe61505f2a0 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 22 Oct 2025 18:28:09 +0200 Subject: [PATCH 2/4] modules: move introspection module into inventoryClass submodule --- modules/inventoryClass/default.nix | 14 ++++++++++++- .../inventory-introspection.nix | 20 ------------------- 2 files changed, 13 insertions(+), 21 deletions(-) delete mode 100644 modules/inventoryClass/inventory-introspection.nix diff --git a/modules/inventoryClass/default.nix b/modules/inventoryClass/default.nix index 0a95378ec..a680b5607 100644 --- a/modules/inventoryClass/default.nix +++ b/modules/inventoryClass/default.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib, clanLib, config, ... }: let inherit (lib) types mkOption; submodule = m: types.submoduleWith { modules = [ m ]; }; @@ -23,5 +23,17 @@ in }; })); }; + introspection = lib.mkOption { + readOnly = true; + # TODO: use options.inventory instead of the evaluate config attribute + default = + builtins.removeAttrs (clanLib.introspection.getPrios { options = config.inventory.options; }) + # tags are freeformType which is not supported yet. + # services is removed and throws an error if accessed. + [ + "tags" + "services" + ]; + }; }; } diff --git a/modules/inventoryClass/inventory-introspection.nix b/modules/inventoryClass/inventory-introspection.nix deleted file mode 100644 index 29ab52eec..000000000 --- a/modules/inventoryClass/inventory-introspection.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ - config, - lib, - clanLib, - ... -}: -{ - options.introspection = lib.mkOption { - readOnly = true; - # TODO: use options.inventory instead of the evaluate config attribute - default = - builtins.removeAttrs (clanLib.introspection.getPrios { options = config.inventory.options; }) - # tags are freeformType which is not supported yet. - # services is removed and throws an error if accessed. - [ - "tags" - "services" - ]; - }; -} From 410d0d05322cc6492a44dea080ca063d4e6b2655 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 22 Oct 2025 18:31:12 +0200 Subject: [PATCH 3/4] modules: move input-mapping into inventoryClass submodule --- modules/clan/module.nix | 6 +-- modules/inventoryClass/default.nix | 75 +++++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 6 deletions(-) diff --git a/modules/clan/module.nix b/modules/clan/module.nix index d3db7cbf9..3c587d4cf 100644 --- a/modules/clan/module.nix +++ b/modules/clan/module.nix @@ -229,11 +229,8 @@ in }; imports = [ ../inventoryClass/default.nix - (lib.modules.importApply ../inventoryClass/service-list-from-inputs.nix { - inherit flakeInputs clanLib; - }) { - inherit inventory directory; + inherit inventory directory flakeInputs; } ( let @@ -252,7 +249,6 @@ in machines = config.distributedServices.allMachines; } ) - ../inventoryClass/inventory-introspection.nix ]; }; diff --git a/modules/inventoryClass/default.nix b/modules/inventoryClass/default.nix index a680b5607..a618f95d2 100644 --- a/modules/inventoryClass/default.nix +++ b/modules/inventoryClass/default.nix @@ -1,10 +1,38 @@ -{ lib, clanLib, config, ... }: +{ + lib, + clanLib, + config, + ... +}: let inherit (lib) types mkOption; submodule = m: types.submoduleWith { modules = [ m ]; }; + + inspectModule = + inputName: moduleName: module: + let + eval = clanLib.evalService { + modules = [ module ]; + prefix = [ + inputName + "clan" + "modules" + moduleName + ]; + }; + in + { + manifest = eval.config.manifest; + roles = lib.mapAttrs (_n: v: { inherit (v) description; }) eval.config.roles; + }; + in { options = { + flakeInputs = mkOption { + type = types.raw; + }; + directory = mkOption { type = types.path; }; @@ -35,5 +63,50 @@ in "services" ]; }; + + staticModules = lib.mkOption { + readOnly = true; + type = lib.types.raw; + + apply = moduleSet: lib.mapAttrs (inspectModule "") moduleSet; + }; + modulesPerSource = lib.mkOption { + # { sourceName :: { moduleName :: {} }} + readOnly = true; + type = lib.types.raw; + default = + let + inputsWithModules = lib.filterAttrs (_inputName: v: v ? clan.modules) config.flakeInputs; + in + lib.mapAttrs ( + inputName: v: lib.mapAttrs (inspectModule inputName) v.clan.modules + ) inputsWithModules; + }; + moduleSchemas = lib.mkOption { + # { sourceName :: { moduleName :: { roleName :: Schema }}} + readOnly = true; + type = lib.types.raw; + default = lib.mapAttrs ( + _inputName: moduleSet: + lib.mapAttrs ( + _moduleName: module: + (clanLib.evalService { + modules = [ module ]; + prefix = [ ]; + }).config.result.api.schema + ) moduleSet + ) config.modulesPerSource; + }; + templatesPerSource = lib.mkOption { + # { sourceName :: { moduleName :: {} }} + readOnly = true; + type = lib.types.raw; + default = + let + inputsWithTemplates = lib.filterAttrs (_inputName: v: v ? clan.templates) config.flakeInputs; + in + lib.mapAttrs (_inputName: v: lib.mapAttrs (_n: t: t) v.clan.templates) inputsWithTemplates; + + }; }; } From da7ff9a40a2508f0ccf4cb01979546125d3b3ec5 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Wed, 22 Oct 2025 18:47:21 +0200 Subject: [PATCH 4/4] modules/inventory: distributed services output reduce lexical scope --- modules/clan/module.nix | 12 +++++++----- modules/inventoryClass/default.nix | 9 ++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/modules/clan/module.nix b/modules/clan/module.nix index 3c587d4cf..fc0300b2e 100644 --- a/modules/clan/module.nix +++ b/modules/clan/module.nix @@ -231,18 +231,20 @@ in ../inventoryClass/default.nix { inherit inventory directory flakeInputs; + exportsModule = config.exportsModule; } ( - let - clanConfig = config; - in { config, ... }: { staticModules = clan-core.clan.modules; distributedServices = clanLib.inventory.mapInstances { - inherit (clanConfig) inventory exportsModule; - inherit flakeInputs directory; + inherit (config) + inventory + directory + flakeInputs + exportsModule + ; clanCoreModules = clan-core.clan.modules; prefix = [ "distributedServices" ]; }; diff --git a/modules/inventoryClass/default.nix b/modules/inventoryClass/default.nix index a618f95d2..356941fd8 100644 --- a/modules/inventoryClass/default.nix +++ b/modules/inventoryClass/default.nix @@ -32,16 +32,19 @@ in flakeInputs = mkOption { type = types.raw; }; - - directory = mkOption { - type = types.path; + exportsModule = mkOption { + type = types.raw; }; + distributedServices = mkOption { type = types.raw; }; inventory = mkOption { type = types.raw; }; + directory = mkOption { + type = types.path; + }; machines = mkOption { type = types.attrsOf (submodule ({ options = {