don't rebuild eval tests on each ci run

This commit is contained in:
Jörg Thalheim
2025-07-07 20:05:45 +02:00
parent bfb9aaaaef
commit 833e872ccf
4 changed files with 66 additions and 15 deletions

View File

@@ -23,7 +23,13 @@ in
unit-test-module = ( unit-test-module = (
self.clanLib.test.flakeModules.makeEvalChecks { self.clanLib.test.flakeModules.makeEvalChecks {
inherit module; inherit module;
inherit self inputs; inherit inputs;
fileset = lib.fileset.unions [
# The hello-world service being tested
../../clanServices/hello-world
# Required modules
../../nixosModules/clanCore
];
testName = "hello-world"; testName = "hello-world";
tests = ./tests/eval-tests.nix; tests = ./tests/eval-tests.nix;
# Optional arguments passed to the test # Optional arguments passed to the test

View File

@@ -15,7 +15,15 @@ in
unit-test-module = ( unit-test-module = (
self.clanLib.test.flakeModules.makeEvalChecks { self.clanLib.test.flakeModules.makeEvalChecks {
inherit module; inherit module;
inherit self inputs; inherit inputs;
fileset = lib.fileset.unions [
# The zerotier service being tested
../../clanServices/zerotier
# Required modules
../../nixosModules/clanCore
# Dependencies like clan-cli
../../pkgs/clan-cli
];
testName = "zerotier"; testName = "zerotier";
tests = ./tests/eval-tests.nix; tests = ./tests/eval-tests.nix;
testArgs = { }; testArgs = { };

View File

@@ -16,7 +16,7 @@
*/ */
makeEvalChecks = makeEvalChecks =
{ {
self, fileset,
inputs, inputs,
testName, testName,
tests, tests,
@@ -24,7 +24,7 @@
testArgs ? { }, testArgs ? { },
}: }:
let let
inputOverrides = self.clanLib.flake-inputs.getOverrides inputs; inputOverrides = clanLib.flake-inputs.getOverrides inputs;
attrName = "eval-tests-${testName}"; attrName = "eval-tests-${testName}";
in in
{ {
@@ -39,14 +39,42 @@
} }
// testArgs // testArgs
); );
checks.${attrName} = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } '' checks.${attrName} =
let
# The root is two directories up from where this file is located
root = ../..;
# Combine the user-provided fileset with all flake-module.nix files
# and other essential files
src = lib.fileset.toSource {
inherit root;
fileset = lib.fileset.unions [
# Core flake files
(root + "/flake.nix")
(root + "/flake.lock")
# All flake-module.nix files anywhere in the tree
(lib.fileset.fileFilter (file: file.name == "flake-module.nix") root)
# The flakeModules/clan.nix if it exists
(lib.fileset.maybeMissing (root + "/flakeModules/clan.nix"))
# Core libraries
(root + "/lib")
# User-provided fileset
fileset
];
};
in
pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
export HOME="$(realpath .)" export HOME="$(realpath .)"
nix-unit --eval-store "$HOME" \ nix-unit --eval-store "$HOME" \
--extra-experimental-features flakes \ --extra-experimental-features flakes \
--show-trace \ --show-trace \
${inputOverrides} \ ${inputOverrides} \
--flake ${self}#legacyPackages.${system}.${attrName} --flake ${src}#legacyPackages.${system}.${attrName}
touch $out touch $out
''; '';

View File

@@ -1,4 +1,9 @@
{ self, inputs, ... }: {
self,
inputs,
lib,
...
}:
{ {
perSystem = perSystem =
{ ... }: { ... }:
@@ -10,7 +15,11 @@
test-types-module = ( test-types-module = (
self.clanLib.test.flakeModules.makeEvalChecks { self.clanLib.test.flakeModules.makeEvalChecks {
module = throw ""; module = throw "";
inherit self inputs; inherit inputs;
fileset = lib.fileset.unions [
# Only lib is needed for type tests
../../lib
];
testName = "types"; testName = "types";
tests = ./tests.nix; tests = ./tests.nix;
# Optional arguments passed to the test # Optional arguments passed to the test