From ba3a026f40c68e7b627ac2ff7b62dac014d513fd Mon Sep 17 00:00:00 2001 From: rootile Date: Sun, 14 Jun 2026 18:45:40 +0200 Subject: [PATCH] tests: migrate eval-store.sh Change-Id: Id4a721871218160b441e848f6f252c06187320bf --- tests/functional/eval-store.sh | 50 -------------- tests/functional/meson.build | 1 - tests/functional2/eval/test_eval_store.py | 69 +++++++++++++++++++ .../functional2/testlib/global_assets/ifd.nix | 10 +++ 4 files changed, 79 insertions(+), 51 deletions(-) delete mode 100644 tests/functional/eval-store.sh create mode 100644 tests/functional2/eval/test_eval_store.py create mode 100644 tests/functional2/testlib/global_assets/ifd.nix diff --git a/tests/functional/eval-store.sh b/tests/functional/eval-store.sh deleted file mode 100644 index 9937ecbce..000000000 --- a/tests/functional/eval-store.sh +++ /dev/null @@ -1,50 +0,0 @@ -source common.sh - -# Using `--eval-store` with the daemon will eventually copy everything -# to the build store, invalidating most of the tests here -needLocalStore "“--eval-store” doesn't achieve much with the daemon" - -eval_store=$TEST_ROOT/eval-store - -clearStore -rm -rf "$eval_store" - -nix build -f dependencies.nix --eval-store "$eval_store" -o "$TEST_ROOT/result" -[[ -e $TEST_ROOT/result/foobar ]] -if [[ ! -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then - # Resolved CA derivations are written to store for building - # - # TODO when we something more systematic - # (https://github.com/NixOS/nix/issues/5025) that distinguishes - # between scratch storage for building and the final destination - # store, we'll be able to make this unconditional again -- resolved - # derivations should only appear in the scratch store. - (! ls $NIX_STORE_DIR/*.drv) -fi -ls $eval_store/nix/store/*.drv - -clearStore -rm -rf "$eval_store" - -nix-instantiate dependencies.nix --eval-store "$eval_store" -(! ls $NIX_STORE_DIR/*.drv) -ls $eval_store/nix/store/*.drv - -clearStore -rm -rf "$eval_store" - -nix-build dependencies.nix --eval-store "$eval_store" -o "$TEST_ROOT/result" -[[ -e $TEST_ROOT/result/foobar ]] -if [[ ! -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then - # See above - (! ls $NIX_STORE_DIR/*.drv) -fi -ls $eval_store/nix/store/*.drv - -clearStore -rm -rf "$eval_store" - -# Confirm that import-from-derivation builds on the build store -[[ $(nix eval --eval-store "$eval_store?require-sigs=false" --impure --raw --file ./ifd.nix) = hi ]] -ls $NIX_STORE_DIR/*dependencies-top/foobar -(! ls $eval_store/nix/store/*dependencies-top/foobar) diff --git a/tests/functional/meson.build b/tests/functional/meson.build index f938a1fba..b33e4d3a7 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -91,7 +91,6 @@ functional_tests_scripts = [ 'nix-copy-ssh-ng.sh', 'pre-hook.sh', 'post-hook.sh', - 'eval-store.sh', 'derivation-json.sh', 'db-migration.sh', 'bash-profile.sh', diff --git a/tests/functional2/eval/test_eval_store.py b/tests/functional2/eval/test_eval_store.py new file mode 100644 index 000000000..8ab4cd47e --- /dev/null +++ b/tests/functional2/eval/test_eval_store.py @@ -0,0 +1,69 @@ +from testlib.utils import get_global_asset +from testlib.fixtures.file_helper import merge_file_declaration +from testlib.fixtures.env import ManagedEnv +from pathlib import Path +from testlib.fixtures.file_helper import with_files +from testlib.utils import get_global_asset_pack +from testlib.fixtures.nix import Nix + + +def assert_only_scratch_drvs(env: ManagedEnv): + assert not list(env.dirs.nix_store_dir.glob("*.drv")) + assert list((env.dirs.home / "eval_store" / "nix" / "store").glob("*.drv")) + + +@with_files(get_global_asset_pack("dependencies")) +def test_nix3_build(nix: Nix, files: Path): + eval_store = files / "eval_store" + res_link = files / "result" + + nix.nix( + ["build", "-f", "dependencies.nix", "--eval-store", eval_store, "-o", res_link], flake=True + ).run().ok() + assert (res_link / "foobar").exists() + + assert_only_scratch_drvs(nix.env) + + +@with_files(get_global_asset_pack("dependencies")) +def test_nix_instantiate(nix: Nix, files: Path): + nix.nix_instantiate(["dependencies.nix", "--eval-store", files / "eval_store"]).run().ok() + assert_only_scratch_drvs(nix.env) + + +@with_files(get_global_asset_pack("dependencies")) +def test_nix_build(nix: Nix, files: Path): + res_link = files / "result" + nix.nix_build( + ["dependencies.nix", "--eval-store", files / "eval_store", "-o", res_link] + ).run().ok() + assert (res_link / "foobar").exists() + assert_only_scratch_drvs(nix.env) + + +@with_files( + merge_file_declaration( + get_global_asset_pack("dependencies"), {"ifd.nix": get_global_asset("ifd.nix")} + ) +) +def test_import_from_derivation_builds(nix: Nix, files: Path): + eval_store = files / "eval_store" + res = ( + nix.nix( + [ + "eval", + "--eval-store", + f"{eval_store}?require-sigs=false", + "--impure", + "--raw", + "--file", + "./ifd.nix", + ], + flake=True, + ) + .run() + .ok() + ) + assert res.stdout_plain == "hi" + assert list(nix.env.dirs.nix_store_dir.glob("*dependencies-top/foobar")) + assert not list((files / "nix" / "store").glob("*dependencies-top/foobar")) diff --git a/tests/functional2/testlib/global_assets/ifd.nix b/tests/functional2/testlib/global_assets/ifd.nix new file mode 100644 index 000000000..d0b9b54ad --- /dev/null +++ b/tests/functional2/testlib/global_assets/ifd.nix @@ -0,0 +1,10 @@ +with import ./config.nix; +import ( + mkDerivation { + name = "foo"; + bla = import ./dependencies.nix {}; + buildCommand = " + echo \\\"hi\\\" > $out + "; + } +)