diff --git a/clanServices/hello-world/flake-module.nix b/clanServices/hello-world/flake-module.nix index 239078ec5..c6330b1a0 100644 --- a/clanServices/hello-world/flake-module.nix +++ b/clanServices/hello-world/flake-module.nix @@ -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 diff --git a/clanServices/zerotier/flake-module.nix b/clanServices/zerotier/flake-module.nix index e1f691fcd..33fe2aa91 100644 --- a/clanServices/zerotier/flake-module.nix +++ b/clanServices/zerotier/flake-module.nix @@ -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 = { }; diff --git a/lib/test/flakeModules.nix b/lib/test/flakeModules.nix index d042d41b4..bfea2d535 100644 --- a/lib/test/flakeModules.nix +++ b/lib/test/flakeModules.nix @@ -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,16 +39,44 @@ } // testArgs ); - checks.${attrName} = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } '' - export HOME="$(realpath .)" + checks.${attrName} = + let + # The root is two directories up from where this file is located + root = ../..; - nix-unit --eval-store "$HOME" \ - --extra-experimental-features flakes \ - --show-trace \ - ${inputOverrides} \ - --flake ${self}#legacyPackages.${system}.${attrName} - touch $out - ''; + # 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 ${src}#legacyPackages.${system}.${attrName} + touch $out + ''; }; } diff --git a/lib/types/flake-module.nix b/lib/types/flake-module.nix index e0e0b58a6..f842e51db 100644 --- a/lib/types/flake-module.nix +++ b/lib/types/flake-module.nix @@ -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