Merge pull request 'Feat(clan.service): init automatic assertions for api schema checks' (#3416) from hsjobeki/clan-core:new-json-schemas into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3416
This commit is contained in:
hsjobeki
2025-04-27 11:07:12 +00:00
2 changed files with 32 additions and 0 deletions

View File

@@ -32,4 +32,21 @@ in
}
);
};
config.result.assertions = lib.optionalAttrs (config.manifest.features.API) (
lib.mapAttrs' (roleName: _role: {
name = "${roleName}";
value = {
message = ''
`roles.${roleName}.interface` is not JSON serializable.
but 'manifest.features.API' is enabled, which requires all 'roles-interfaces' of this module to be a subset of JSON.
clan.service module '${config.manifest.name}
'';
assertion = (builtins.tryEval (lib.deepSeq config.result.api.schema.${roleName} true)).success;
};
}) config.roles
);
}

View File

@@ -450,6 +450,11 @@ in
}) config.roles;
};
result.assertions = mkOption {
default = { };
type = types.attrsOf types.raw;
};
result.allMachines = mkOption {
readOnly = true;
default =
@@ -523,6 +528,16 @@ in
inherit instanceResults;
nixosModule = {
imports = [
# include service assertions:
(
let
failedAssertions = (lib.filterAttrs (_: v: !v.assertion) config.result.assertions);
in
{
assertions = lib.attrValues failedAssertions;
}
)
# For error backtracing. This module was produced by the 'perMachine' function
# TODO: check if we need this or if it leads to better errors if we pass the underlying module locations
# (lib.setDefaultModuleLocation "clan.service: ${config.manifest.name} - via perMachine" machineResult.nixosModule)