diff --git a/checks/flake-module.nix b/checks/flake-module.nix new file mode 100644 index 00000000..b826c2a1 --- /dev/null +++ b/checks/flake-module.nix @@ -0,0 +1,5 @@ +{ + imports = [ + ./schema.nix + ]; +} diff --git a/checks/schema.nix b/checks/schema.nix new file mode 100644 index 00000000..4a5dae63 --- /dev/null +++ b/checks/schema.nix @@ -0,0 +1,50 @@ +{ self, lib, inputs, ... }: +let + inherit (builtins) + mapAttrs + toJSON + toFile + ; + inherit (lib) + mapAttrs' + ; + clanLib = self.lib; + clanModules = self.clanModules; + + baseModule = { + imports = + (import (inputs.nixpkgs + "/nixos/modules/module-list.nix")) + ++ [{ + nixpkgs.hostPlatform = "x86_64-linux"; + }]; + }; + + optionsFromModule = module: + let + evaled = lib.evalModules { + modules = [ module baseModule ]; + }; + in + evaled.options.clan.networking; + + clanModuleSchemas = mapAttrs (_: module: clanLib.jsonschema.parseOptions (optionsFromModule module)) clanModules; + +in +{ + perSystem = { pkgs, ... }: + let + mkTest = name: schema: pkgs.runCommand "schema-${name}" { } '' + ${pkgs.check-jsonschema}/bin/check-jsonschema \ + --check-metaschema ${toFile "schema-${name}" (toJSON schema)} + touch $out + ''; + in + { + checks = mapAttrs' + (name: schema: { + name = "schema-${name}"; + value = mkTest name schema; + }) + clanModuleSchemas; + }; +} diff --git a/flake.nix b/flake.nix index 50d88a32..a898dd3f 100644 --- a/flake.nix +++ b/flake.nix @@ -22,7 +22,7 @@ "aarch64-linux" ]; imports = [ - # ./checks/flake-module.nix + ./checks/flake-module.nix ./devShell.nix ./formatter.nix ./templates/flake-module.nix