Ext/modules: expose module schemas

This commit is contained in:
Johannes Kirschbauer
2024-11-21 16:41:25 +01:00
parent ec48be6e54
commit de4c6caf30
5 changed files with 31 additions and 14 deletions

View File

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

View File

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

View File

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

View File

@@ -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

View File

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