Checks: add json-compat check wrapper to ensure all clan.modules stay json-compatible

This commit is contained in:
Johannes Kirschbauer
2025-04-29 15:31:02 +02:00
parent a4a1363195
commit 3d09c98ed3
3 changed files with 34 additions and 6 deletions

View File

@@ -64,7 +64,33 @@ in
self'.legacyPackages.homeConfigurations or { } self'.legacyPackages.homeConfigurations or { }
); );
in in
nixosTests // flakeOutputs; nixosTests
// flakeOutputs
// {
# TODO: Automatically provide this check to downstream users to check their modules
clan-modules-json-compatible =
let
allSchemas = lib.mapAttrs (
_n: m:
let
schema =
(self.clanLib.inventory.evalClanService {
modules = [ m ];
key = "checks";
}).config.result.api.schema;
in
schema
) self.clan.modules;
in
pkgs.runCommand "combined-result"
{
schemaFile = builtins.toFile "schemas.json" (builtins.toJSON allSchemas);
}
''
mkdir -p $out
cat $schemaFile > $out/allSchemas.json
'';
};
legacyPackages = { legacyPackages = {
nixosTests = nixosTests =
let let

View File

@@ -13,6 +13,9 @@ in
clan.inventory.modules = { clan.inventory.modules = {
hello-world = module; hello-world = module;
}; };
clan.modules = {
hello-world = module;
};
perSystem = perSystem =
{ pkgs, ... }: { pkgs, ... }:
let let

View File

@@ -16,18 +16,17 @@
}: }:
let let
evalClanService = evalClanService =
{ modules, id }: { modules, key }:
(lib.evalModules { (lib.evalModules {
class = "clan.service"; class = "clan.service";
modules = [ modules = [
./service-module.nix ./service-module.nix
# feature modules # feature modules
(lib.modules.importApply ./api-feature.nix { (lib.modules.importApply ./api-feature.nix {
inherit clanLib; inherit clanLib;
attrName = id; attrName = key;
}) })
]; ] ++ modules;
}); });
in in
{ {
@@ -139,7 +138,7 @@ in
importedModulesEvaluated = lib.mapAttrs ( importedModulesEvaluated = lib.mapAttrs (
module_ident: instances: module_ident: instances:
evalClanService { evalClanService {
id = module_ident; key = module_ident;
modules = modules =
[ [
# Import the resolved module. # Import the resolved module.