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 afab33056e
commit 00914311a4
4 changed files with 66 additions and 15 deletions

View File

@@ -23,7 +23,13 @@ in
unit-test-module = (
self.clanLib.test.flakeModules.makeEvalChecks {
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";
tests = ./tests/eval-tests.nix;
# Optional arguments passed to the test

View File

@@ -15,7 +15,15 @@ in
unit-test-module = (
self.clanLib.test.flakeModules.makeEvalChecks {
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";
tests = ./tests/eval-tests.nix;
testArgs = { };

View File

@@ -16,7 +16,7 @@
*/
makeEvalChecks =
{
self,
fileset,
inputs,
testName,
tests,
@@ -24,7 +24,7 @@
testArgs ? { },
}:
let
inputOverrides = self.clanLib.flake-inputs.getOverrides inputs;
inputOverrides = clanLib.flake-inputs.getOverrides inputs;
attrName = "eval-tests-${testName}";
in
{
@@ -39,14 +39,42 @@
}
// 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 .)"
nix-unit --eval-store "$HOME" \
--extra-experimental-features flakes \
--show-trace \
${inputOverrides} \
--flake ${self}#legacyPackages.${system}.${attrName}
--flake ${src}#legacyPackages.${system}.${attrName}
touch $out
'';

View File

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