diff --git a/tests/functional/meson.build b/tests/functional/meson.build index b65f9f599..b6fc3502e 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -140,7 +140,6 @@ functional_tests_scripts = [ 'eval-store.sh', 'derivation-json.sh', 'import-derivation.sh', - 'nix_path.sh', 'case-hack.sh', 'placeholders.sh', 'ssh-relay.sh', diff --git a/tests/functional/nix_path.sh b/tests/functional/nix_path.sh deleted file mode 100644 index 2b222b4a1..000000000 --- a/tests/functional/nix_path.sh +++ /dev/null @@ -1,14 +0,0 @@ -# Regression for https://github.com/NixOS/nix/issues/5998 and https://github.com/NixOS/nix/issues/5980 - -source common.sh - -export NIX_PATH=non-existent=/non-existent/but-unused-anyways:by-absolute-path=$PWD:by-relative-path=. - -nix-instantiate --eval -E '' --restrict-eval -nix-instantiate --eval -E '' --restrict-eval - -# Should ideally also test this, but there’s no pure way to do it, so just trust me that it works -# nix-instantiate --eval -E '' -I nixpkgs=channel:nixos-unstable --restrict-eval - -[[ $(nix-instantiate --find-file by-absolute-path/simple.nix) = $PWD/simple.nix ]] -[[ $(nix-instantiate --find-file by-relative-path/simple.nix) = $PWD/simple.nix ]] diff --git a/tests/functional2/eval/test_nix_path.py b/tests/functional2/eval/test_nix_path.py new file mode 100644 index 000000000..9c62cabab --- /dev/null +++ b/tests/functional2/eval/test_nix_path.py @@ -0,0 +1,45 @@ +import pytest + +from functional2.testlib.fixtures.env import ManagedEnv +from functional2.testlib.fixtures.file_helper import with_files +from functional2.testlib.fixtures.nix import Nix +from functional2.testlib.utils import get_global_asset + + +@with_files({"trivial.nix": get_global_asset("trivial.nix")}) +@pytest.mark.parametrize("prefix", ["by-absolute-path", "by-relative-path"]) +def test_nix_path(env: ManagedEnv, nix: Nix, prefix: str): + env.set_env( + "NIX_PATH", + f"non-existent=/non-existent/but-unused-anyways:by-absolute-path={env.dirs.home}:by-relative-path=.", + ) + + expected_path = str(env.dirs.home / "trivial.nix") + + res = ( + nix.nix_instantiate(["--eval", "-E", f"<{prefix}/trivial.nix>", "--restrict-eval"]) + .run() + .ok() + ) + assert res.stdout_plain == expected_path + res = nix.nix_instantiate(["--find-file", f"{prefix}/trivial.nix"]).run().ok() + path = res.stdout_plain + assert path == expected_path + + +@pytest.mark.skip( + "FIXME(Commentator2.0): for some reason the channel cannot be resolved on the builders" +) +def test_nix_path_nixpkgs(env: ManagedEnv, nix: Nix): + env.set_env( + "NIX_PATH", + f"non-existent=/non-existent/but-unused-anyways:by-absolute-path={env.dirs.home}:by-relative-path=.", + ) + res = ( + nix.nix_instantiate( + ["--eval", "-E", "", "-I", "nixpkgs=channel:nixos-unstable", "--restrict-eval"] + ) + .run() + .ok() + ) + assert str(env.dirs.nix_store_dir) in res.stdout_plain