From a2648f2afb35adc2f4df6a06b6399c93d3320f93 Mon Sep 17 00:00:00 2001 From: DavHau Date: Wed, 9 Aug 2023 18:38:44 +0200 Subject: [PATCH 1/2] clan-cli: prepare source in extra derivation Towards not rebuilding clan-cli on each commit --- pkgs/clan-cli/default.nix | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/pkgs/clan-cli/default.nix b/pkgs/clan-cli/default.nix index d590bc77..9dc255be 100644 --- a/pkgs/clan-cli/default.nix +++ b/pkgs/clan-cli/default.nix @@ -29,10 +29,19 @@ let ]; checkPython = python3.withPackages (_ps: dependencies ++ testDependencies); + + # - vendor the jsonschema nix lib (copy instead of symlink). + # - lib.cleanSource prevents unnecessary rebuilds when `self` changes. + source = runCommand "clan-cli-source" { } '' + cp -r ${lib.cleanSource ./.} $out + chmod -R +w $out + rm $out/clan_cli/config/jsonschema + cp -r ${lib.cleanSource (self + /lib/jsonschema)} $out/clan_cli/config/jsonschema + ''; in python3.pkgs.buildPythonPackage { name = "clan-cli"; - src = lib.cleanSource ./.; + src = source; format = "pyproject"; nativeBuildInputs = [ setuptools @@ -40,16 +49,11 @@ python3.pkgs.buildPythonPackage { ]; propagatedBuildInputs = dependencies; - preBuild = '' - rm ./clan_cli/config/jsonschema - cp -r ${self}/lib/jsonschema ./clan_cli/config/jsonschema - ''; - passthru.tests = { clan-mypy = runCommand "clan-mypy" { } '' - cp -r ${self} ./flake - chmod +w -R ./flake - cd ./flake/pkgs/clan-cli + cp -r ${source} ./src + chmod +w -R ./src + cd ./src ${checkPython}/bin/mypy . touch $out ''; @@ -57,9 +61,9 @@ python3.pkgs.buildPythonPackage { { nativeBuildInputs = [ age zerotierone bubblewrap sops nix ]; } '' - cp -r ${self} ./flake - chmod +w -R ./flake - cd ./flake/pkgs/clan-cli + cp -r ${source} ./src + chmod +w -R ./src + cd ./src ${checkPython}/bin/python -m pytest ./tests touch $out ''; From 00826d848ebac59f46ec51da89cc2d32ac88c536 Mon Sep 17 00:00:00 2001 From: DavHau Date: Wed, 9 Aug 2023 18:42:03 +0200 Subject: [PATCH 2/2] checks: ensure clanModules are clan-config compatible --- checks/flake-module.nix | 5 +++++ checks/schema.nix | 50 +++++++++++++++++++++++++++++++++++++++++ flake.nix | 2 +- 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 checks/flake-module.nix create mode 100644 checks/schema.nix 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