From 662787f96e7219b21c10d17744fe2cabaf4e8871 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Tue, 29 Apr 2025 15:31:02 +0200 Subject: [PATCH] Checks: add json-compat check wrapper to ensure all clan.modules stay json-compatible --- checks/flake-module.nix | 28 ++++++++++++++++++- clanServices/hello-world/flake-module.nix | 3 ++ .../distributed-service/inventory-adapter.nix | 9 +++--- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/checks/flake-module.nix b/checks/flake-module.nix index 33c3d41f4..04480c7e1 100644 --- a/checks/flake-module.nix +++ b/checks/flake-module.nix @@ -64,7 +64,33 @@ in self'.legacyPackages.homeConfigurations or { } ); 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 = { nixosTests = let diff --git a/clanServices/hello-world/flake-module.nix b/clanServices/hello-world/flake-module.nix index c76eca5a8..9a1c14a27 100644 --- a/clanServices/hello-world/flake-module.nix +++ b/clanServices/hello-world/flake-module.nix @@ -13,6 +13,9 @@ in clan.inventory.modules = { hello-world = module; }; + clan.modules = { + hello-world = module; + }; perSystem = { pkgs, ... }: let diff --git a/lib/inventory/distributed-service/inventory-adapter.nix b/lib/inventory/distributed-service/inventory-adapter.nix index 92a134ac2..e899564c8 100644 --- a/lib/inventory/distributed-service/inventory-adapter.nix +++ b/lib/inventory/distributed-service/inventory-adapter.nix @@ -16,18 +16,17 @@ }: let evalClanService = - { modules, id }: + { modules, key }: (lib.evalModules { class = "clan.service"; modules = [ ./service-module.nix - # feature modules (lib.modules.importApply ./api-feature.nix { inherit clanLib; - attrName = id; + attrName = key; }) - ]; + ] ++ modules; }); in { @@ -139,7 +138,7 @@ in importedModulesEvaluated = lib.mapAttrs ( module_ident: instances: evalClanService { - id = module_ident; + key = module_ident; modules = [ # Import the resolved module.