From 74799dd97cea1ae09d62d25124226d5f058130d5 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Thu, 14 Aug 2025 19:10:08 +0300 Subject: [PATCH 1/5] lib/tests/misc: don't import nixpkgs --- lib/tests/misc.nix | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index d9a72b29f2f4..4c313931295c 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -145,6 +145,11 @@ let inherit expected; }; + dummyDerivation = derivation { + name = "name"; + builder = "builder"; + system = "system"; + }; in runTests { @@ -757,13 +762,7 @@ runTests { }; testSplitStringsDerivation = { - expr = take 3 ( - strings.splitString "/" (derivation { - name = "name"; - builder = "builder"; - system = "system"; - }) - ); + expr = take 3 (strings.splitString "/" dummyDerivation); expected = [ "" "nix" @@ -816,7 +815,7 @@ runTests { in { storePath = isStorePath goodPath; - storePathDerivation = isStorePath (import ../.. { system = "x86_64-linux"; }).hello; + storePathDerivation = isStorePath dummyDerivation; storePathAppendix = isStorePath "${goodPath}/bin/python"; nonAbsolute = isStorePath (concatStrings (tail (stringToCharacters goodPath))); asPath = isStorePath (/. + goodPath); @@ -901,7 +900,7 @@ runTests { }; testHasInfixDerivation = { - expr = hasInfix "hello" (import ../.. { system = "x86_64-linux"; }).hello; + expr = hasInfix "name" dummyDerivation; expected = true; }; From 76a7b540835ef7a7aed2253c7c3e620a5379cfef Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Thu, 14 Aug 2025 19:18:08 +0300 Subject: [PATCH 2/5] lib/tests/misc: don't hardcode store directory --- lib/tests/misc.nix | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index 4c313931295c..b30ae32b2330 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -762,12 +762,8 @@ runTests { }; testSplitStringsDerivation = { - expr = take 3 (strings.splitString "/" dummyDerivation); - expected = [ - "" - "nix" - "store" - ]; + expr = lib.dropEnd 1 (strings.splitString "/" dummyDerivation); + expected = strings.splitString "/" builtins.storeDir; }; testSplitVersionSingle = { From 67ef2657ff6e3e8ece62a7a08b4231573a052a15 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Thu, 14 Aug 2025 19:22:35 +0300 Subject: [PATCH 3/5] lib/tests/test-with-nix: run misc.nix tests in the derivation This would have allowed us to catch to fromTOML regression in [1] without waiting for the dogfooding on master, since previously these tests [2] were not run for the Nix/Lix under test - only the host nix. [1]: https://github.com/NixOS/nix/pull/13741 [2]: https://github.com/NixOS/nixpkgs/pull/433710 --- lib/tests/test-with-nix.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/tests/test-with-nix.nix b/lib/tests/test-with-nix.nix index ebbe5e0ae5cd..36db15ab32c8 100644 --- a/lib/tests/test-with-nix.nix +++ b/lib/tests/test-with-nix.nix @@ -71,6 +71,9 @@ pkgs.runCommand "nixpkgs-lib-tests-nix-${nix.version}" echo "Running lib/tests/systems.nix" [[ $(nix-instantiate --eval --strict lib/tests/systems.nix | tee /dev/stderr) == '[ ]' ]]; + echo "Running lib/tests/misc.nix" + [[ $(nix-instantiate --eval --strict lib/tests/misc.nix | tee /dev/stderr) == '[ ]' ]]; + mkdir $out echo success > $out/${nix.version} '' From c2698371ef823bb2158015a39347576ce0fcffe3 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Thu, 14 Aug 2025 22:46:59 +0300 Subject: [PATCH 4/5] lib/tests/test-with-nix: remove broken import ./check-eval This doesn't do the right thing here, because it evaluates the test with nix that is evaluating the `nixpkgs-lib-tests-nix-${nix.version}` derivation, not the Nix/Lix under test. This was just really busted for a long time. --- lib/tests/check-eval.nix | 10 ---------- lib/tests/test-with-nix.nix | 1 - 2 files changed, 11 deletions(-) delete mode 100644 lib/tests/check-eval.nix diff --git a/lib/tests/check-eval.nix b/lib/tests/check-eval.nix deleted file mode 100644 index 2ef7580e5857..000000000000 --- a/lib/tests/check-eval.nix +++ /dev/null @@ -1,10 +0,0 @@ -# Throws an error if any of our lib tests fail. - -let - tests = [ - "misc" - "systems" - ]; - all = builtins.concatLists (map (f: import (./. + "/${f}.nix")) tests); -in -if all == [ ] then null else throw (builtins.toJSON all) diff --git a/lib/tests/test-with-nix.nix b/lib/tests/test-with-nix.nix index 36db15ab32c8..4e13eef4c5b1 100644 --- a/lib/tests/test-with-nix.nix +++ b/lib/tests/test-with-nix.nix @@ -18,7 +18,6 @@ pkgs.runCommand "nixpkgs-lib-tests-nix-${nix.version}" { buildInputs = [ - (import ./check-eval.nix) (import ./fetchers.nix) (import ../path/tests { inherit pkgs; From 609c8799fa2f2d85d4d709f826f740b69cbdaba9 Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Thu, 14 Aug 2025 22:51:59 +0300 Subject: [PATCH 5/5] lib/tests/test-with-nix: run lib/tests/fetchers.nix in the derivation This suffers from the same issue as misc.nix tests, because they were evaluated by the host nix, not the one that is being tested. --- lib/tests/test-with-nix.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/tests/test-with-nix.nix b/lib/tests/test-with-nix.nix index 4e13eef4c5b1..4fc65010b878 100644 --- a/lib/tests/test-with-nix.nix +++ b/lib/tests/test-with-nix.nix @@ -18,7 +18,6 @@ pkgs.runCommand "nixpkgs-lib-tests-nix-${nix.version}" { buildInputs = [ - (import ./fetchers.nix) (import ../path/tests { inherit pkgs; }) @@ -73,6 +72,9 @@ pkgs.runCommand "nixpkgs-lib-tests-nix-${nix.version}" echo "Running lib/tests/misc.nix" [[ $(nix-instantiate --eval --strict lib/tests/misc.nix | tee /dev/stderr) == '[ ]' ]]; + echo "Running lib/tests/fetchers.nix" + [[ $(nix-instantiate --eval --strict lib/tests/fetchers.nix | tee /dev/stderr) == '[ ]' ]]; + mkdir $out echo success > $out/${nix.version} ''