modules: move input-mapping into inventoryClass submodule

This commit is contained in:
Johannes Kirschbauer
2025-10-22 18:31:12 +02:00
parent a25d983c87
commit 410d0d0532
2 changed files with 75 additions and 6 deletions

View File

@@ -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
];
};

View File

@@ -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 "<clan-core>") 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;
};
};
}