diff --git a/lib/build-clan/interface.nix b/lib/build-clan/interface.nix index 1ed9b0314..baf1a45fb 100644 --- a/lib/build-clan/interface.nix +++ b/lib/build-clan/interface.nix @@ -101,8 +101,12 @@ in # Those options are interfaced by the CLI # We don't specify the type here, for better performance. inventory = lib.mkOption { type = lib.types.raw; }; + # all inventory module schemas + moduleSchemas = lib.mkOption { type = lib.types.raw; }; inventoryFile = lib.mkOption { type = lib.types.raw; }; + # The machine 'imports' generated by the inventory per machine serviceConfigs = lib.mkOption { type = lib.types.raw; }; + # clan-core's modules clanModules = lib.mkOption { type = lib.types.raw; }; source = lib.mkOption { type = lib.types.raw; }; meta = lib.mkOption { type = lib.types.raw; }; diff --git a/lib/build-clan/module.nix b/lib/build-clan/module.nix index 74deadfb5..a579f9973 100644 --- a/lib/build-clan/module.nix +++ b/lib/build-clan/module.nix @@ -169,6 +169,7 @@ in inherit nixosConfigurations; clanInternals = { + moduleSchemas = clan-core.lib.modules.getModulesSchema config.inventory.modules; inherit serviceConfigs; inherit (clan-core) clanModules; inherit inventoryFile; diff --git a/lib/default.nix b/lib/default.nix index 4b88491cb..e1ab88473 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -16,5 +16,8 @@ in facts = import ./facts.nix { inherit lib; }; inventory = import ./inventory { inherit lib clan-core; }; jsonschema = import ./jsonschema { inherit lib; }; - modules = import ./frontmatter { inherit lib; }; + modules = import ./frontmatter { + inherit lib; + self = clan-core; + }; } diff --git a/lib/frontmatter/default.nix b/lib/frontmatter/default.nix index e200f0b01..cd8a302f4 100644 --- a/lib/frontmatter/default.nix +++ b/lib/frontmatter/default.nix @@ -1,8 +1,20 @@ -{ lib }: +{ lib, self }: let # Trim the .nix extension from a filename trimExtension = name: builtins.substring 0 (builtins.stringLength name - 4) name; + jsonWithoutHeader = self.lib.jsonschema { + includeDefaults = true; + header = { }; + }; + + getModulesSchema = + modules: + lib.mapAttrs ( + _moduleName: rolesOptions: + lib.mapAttrs (_roleName: options: jsonWithoutHeader.parseOptions options { }) rolesOptions + ) (self.lib.evalClanModulesWithRoles modules); + evalFrontmatter = { moduleName, @@ -90,7 +102,7 @@ in { inherit frontmatterOptions - + getModulesSchema getFrontmatter checkConstraints diff --git a/lib/inventory/schemas/default.nix b/lib/inventory/schemas/default.nix index 56d508918..6918368a5 100644 --- a/lib/inventory/schemas/default.nix +++ b/lib/inventory/schemas/default.nix @@ -6,21 +6,17 @@ ... }: let - includeDefaults = true; # { mName :: { roleName :: Options } } - modulesRolesOptions = self.lib.evalClanModulesWithRoles self.clanModules; - modulesSchema = lib.mapAttrs ( - _moduleName: rolesOptions: - lib.mapAttrs (_roleName: options: jsonWithoutHeader.parseOptions options { }) rolesOptions - ) modulesRolesOptions; + # getModulesSchema = modules: lib.mapAttrs ( + # _moduleName: rolesOptions: + # lib.mapAttrs (_roleName: options: jsonWithoutHeader.parseOptions options { }) rolesOptions + # ) (self.lib.evalClanModulesWithRoles modules); + + modulesSchema = self.lib.modules.getModulesSchema self.clanModules; jsonLib = self.lib.jsonschema { inherit includeDefaults; }; - - jsonWithoutHeader = self.lib.jsonschema { - inherit includeDefaults; - header = { }; - }; + includeDefaults = true; frontMatterSchema = jsonLib.parseOptions self.lib.modules.frontmatterOptions { }; @@ -53,6 +49,7 @@ in frontMatterSchema inventorySchema modulesSchema + getModulesSchema renderSchema inventory-schema-abstract ;