tests: migrate eval-store.sh

Change-Id: Id4a721871218160b441e848f6f252c06187320bf
This commit is contained in:
rootile
2026-06-14 18:46:39 +02:00
parent 12baca7bea
commit ba3a026f40
4 changed files with 79 additions and 51 deletions
-50
View File
@@ -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)
-1
View File
@@ -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',
+69
View File
@@ -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"))
@@ -0,0 +1,10 @@
with import ./config.nix;
import (
mkDerivation {
name = "foo";
bla = import ./dependencies.nix {};
buildCommand = "
echo \\\"hi\\\" > $out
";
}
)