testing: migrate flakes/flakes.sh (part 10)
getFlake behavior Change-Id: Iff9bb6e834ff2545db11b72f5a6ab3ddf42e5662
This commit is contained in:
@@ -85,20 +85,6 @@ hash2=$(nix flake metadata flake1 --json --refresh | jq -r .revision)
|
||||
nix build -o $flake1Dir/result git+file://$flake1Dir
|
||||
nix path-info $flake1Dir/result
|
||||
|
||||
# 'getFlake' on an unlocked flakeref should fail in pure mode, but
|
||||
# succeed in impure mode.
|
||||
(! nix build -o $TEST_ROOT/result --expr "(builtins.getFlake \"$flake1Dir\").packages.$system.default")
|
||||
nix build -o $TEST_ROOT/result --expr "(builtins.getFlake \"$flake1Dir\").packages.$system.default" --impure
|
||||
|
||||
# 'getFlake' on a locked flakeref should succeed even in pure mode.
|
||||
nix build -o $TEST_ROOT/result --expr "(builtins.getFlake \"git+file://$flake1Dir?rev=$hash2\").packages.$system.default"
|
||||
|
||||
# Building a flake with an unlocked dependency should fail in pure mode.
|
||||
(! nix eval --expr "builtins.getFlake \"$flake2Dir\"")
|
||||
|
||||
# But should succeed in impure mode.
|
||||
nix eval --expr "builtins.getFlake \"$flake2Dir\"" --impure
|
||||
|
||||
# set up lockfiles for later tests
|
||||
nix build -o $TEST_ROOT/result $flake2Dir#bar --commit-lock-file
|
||||
nix build -o $TEST_ROOT/result $flake3Dir#xyzzy
|
||||
|
||||
@@ -173,6 +173,34 @@ def test_eval_system_takes_effect(nix: Nix, flake1: Path):
|
||||
nix.nix(["build", "--eval-system", "kitty-kitty", flake1]).run().ok()
|
||||
|
||||
|
||||
class TestGetFlake:
|
||||
def test_unlocked_pure_fails(self, nix: Nix, flake1: Path):
|
||||
expr = f'(builtins.getFlake "{flake1}").packages.{system}.default'
|
||||
result = nix.nix(["build", "--expr", expr]).run().expect(1)
|
||||
assert "error: cannot call 'getFlake' on unlocked flake reference" in result.stderr_s
|
||||
|
||||
def test_unlocked_impure_works(self, nix: Nix, flake1: Path):
|
||||
expr = f'(builtins.getFlake "{flake1}").packages.{system}.default'
|
||||
nix.nix(["build", "--impure", "--expr", expr]).run().ok()
|
||||
assert (Path(nix.env.dirs.home / "result/hello")).exists()
|
||||
|
||||
def test_locked_url_pure_works(self, nix: Nix, flake1: Path, git: Git):
|
||||
flake1_original_commit = git(flake1, "rev-parse", "HEAD").stdout_s.strip()
|
||||
expr = f'(builtins.getFlake "git+file://{flake1}?rev={flake1_original_commit}").packages.{system}.default'
|
||||
nix.nix(["build", "--expr", expr]).run().ok()
|
||||
assert (Path(nix.env.dirs.home / "result/hello")).exists()
|
||||
|
||||
def test_unlocked_dep_pure_fails(self, nix: Nix, flake2: Path):
|
||||
# NOTE: this is the same test as test_unlocked_dep_pure_fails because flake2 is not locked,
|
||||
# and flake2 *cannot* be locked because that would also lock flake1 in the flake2 lock file
|
||||
nix.nix(["eval", "--expr", f'(builtins.getFlake "{flake2}")']).run().expect(1)
|
||||
|
||||
@pytest.mark.usefixtures("registry")
|
||||
def test_unlocked_dep_impure_works(self, nix: Nix, flake2: Path):
|
||||
# NOTE: see test above, same thing happens here
|
||||
nix.nix(["eval", "--impure", "--expr", f'(builtins.getFlake "{flake2}")']).run().ok()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("registry")
|
||||
class TestRegistry:
|
||||
def test_registry_list(self, nix: Nix):
|
||||
|
||||
Reference in New Issue
Block a user