testing: migrate flakes/flakes.sh (part 11)
input updates with cli commands Change-Id: Idddfe77a285f9c2cbc4f1463454af539042bc23e
This commit is contained in:
@@ -72,14 +72,10 @@ nix registry add --registry $registry flake3 git+file://$flake3Dir
|
||||
nix registry add --registry $registry flake4 flake3
|
||||
nix registry add --registry $registry nixpkgs flake1
|
||||
|
||||
json=$(nix flake metadata flake1 --json | jq .)
|
||||
hash1=$(echo "$json" | jq -r .revision)
|
||||
|
||||
echo foo > $flake1Dir/foo
|
||||
git -C $flake1Dir add $flake1Dir/foo
|
||||
echo -n '# foo' >> $flake1Dir/flake.nix
|
||||
git -C $flake1Dir commit -a -m 'Foo'
|
||||
hash2=$(nix flake metadata flake1 --json --refresh | jq -r .revision)
|
||||
|
||||
# Check that store symlinks inside a flake are not interpreted as flakes.
|
||||
nix build -o $flake1Dir/result git+file://$flake1Dir
|
||||
@@ -336,39 +332,3 @@ EOF
|
||||
nix flake update --flake "$flake3Dir"
|
||||
[[ $(jq -c .nodes.flake2.inputs.flake1 "$flake3Dir/flake.lock") =~ '["foo"]' ]]
|
||||
[[ $(jq .nodes.foo.locked.url "$flake3Dir/flake.lock") =~ flake7 ]]
|
||||
|
||||
# prepare path flakes.
|
||||
mkdir -p $flake5Dir
|
||||
writeDependentFlake $flake5Dir
|
||||
nix flake lock path://$flake5Dir
|
||||
|
||||
# Test tarball flakes.
|
||||
tar cfz $TEST_ROOT/flake.tar.gz -C $TEST_ROOT flake5
|
||||
|
||||
# Test --override-input.
|
||||
git -C $flake3Dir reset --hard
|
||||
nix flake lock $flake3Dir --override-input flake2/flake1 file://$TEST_ROOT/flake.tar.gz -vvvvv
|
||||
[[ $(jq .nodes.flake1_2.locked.url $flake3Dir/flake.lock) =~ flake.tar.gz ]]
|
||||
|
||||
nix flake lock $flake3Dir --override-input flake2/flake1 flake1
|
||||
[[ $(jq -r .nodes.flake1_2.locked.rev $flake3Dir/flake.lock) =~ $hash2 ]]
|
||||
|
||||
nix flake lock $flake3Dir --override-input flake2/flake1 flake1/master/$hash1
|
||||
[[ $(jq -r .nodes.flake1_2.locked.rev $flake3Dir/flake.lock) =~ $hash1 ]]
|
||||
|
||||
nix flake lock $flake3Dir
|
||||
[[ $(jq -r .nodes.flake1_2.locked.rev $flake3Dir/flake.lock) = $hash1 ]]
|
||||
|
||||
# Test updating an individual input of a flake lockfile.
|
||||
nix flake update flake2/flake1 --flake "$flake3Dir"
|
||||
[[ $(jq -r .nodes.flake1_2.locked.rev "$flake3Dir/flake.lock") =~ $hash2 ]]
|
||||
|
||||
# Test updating multiple inputs.
|
||||
nix flake lock "$flake3Dir" --override-input flake1 flake1/master/$hash1
|
||||
nix flake lock "$flake3Dir" --override-input flake2/flake1 flake1/master/$hash1
|
||||
[[ $(jq -r .nodes.flake1.locked.rev "$flake3Dir/flake.lock") =~ $hash1 ]]
|
||||
[[ $(jq -r .nodes.flake1_2.locked.rev "$flake3Dir/flake.lock") =~ $hash1 ]]
|
||||
|
||||
nix flake update flake1 flake2/flake1 --flake "$flake3Dir"
|
||||
[[ $(jq -r .nodes.flake1.locked.rev "$flake3Dir/flake.lock") =~ $hash2 ]]
|
||||
[[ $(jq -r .nodes.flake1_2.locked.rev "$flake3Dir/flake.lock") =~ $hash2 ]]
|
||||
|
||||
@@ -2,6 +2,7 @@ from pathlib import Path
|
||||
import pytest
|
||||
import re
|
||||
import tarfile
|
||||
import json
|
||||
|
||||
from testlib.fixtures.nix import Nix
|
||||
from testlib.fixtures.env import ManagedEnv
|
||||
@@ -54,6 +55,7 @@ flake3_files = {
|
||||
}
|
||||
}
|
||||
flake5_files = {"flake5": dependent_flake()}
|
||||
nonflake_files = {"nonFlake": get_global_asset_pack(".git") | {"README.md": File("FNORD")}}
|
||||
|
||||
|
||||
def _make_flake_repo(
|
||||
@@ -89,6 +91,37 @@ def flake3(git: Git, env: ManagedEnv, request: pytest.FixtureRequest) -> Path:
|
||||
return _make_flake_repo("flake3", flake3_files, git, env, request)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def flake3_medium(git: Git, env: ManagedEnv, nix: Nix, flake3: Path, nonflake: Path) -> Path: # noqa: ARG001
|
||||
(flake3 / "flake.nix").write_text(f"""{{
|
||||
inputs = {{
|
||||
nonFlake = {{
|
||||
url = "{env.dirs.test_root}/nonFlake";
|
||||
flake = false;
|
||||
}};
|
||||
}};
|
||||
|
||||
description = "Fnord";
|
||||
|
||||
outputs = {{ self, flake1, flake2, nonFlake }}: rec {{
|
||||
packages.{system}.sth = flake1.packages.{system}.foo;
|
||||
packages.{system}.fnord =
|
||||
with import ./config.nix;
|
||||
mkDerivation {{
|
||||
inherit system;
|
||||
name = "fnord";
|
||||
buildCommand = ''
|
||||
cat ${{nonFlake}}/README.md > $out
|
||||
'';
|
||||
}};
|
||||
}};
|
||||
}}""")
|
||||
nix.nix(["flake", "lock", flake3]).run().ok()
|
||||
git(flake3, "add", "flake.nix", "flake.lock")
|
||||
git(flake3, "commit", "-m", "medium config")
|
||||
return flake3
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def flake5(env: ManagedEnv, request: pytest.FixtureRequest) -> Path:
|
||||
_init_files(flake5_files, env.dirs.test_root, request.path.parent, env)
|
||||
@@ -104,6 +137,12 @@ def flake5_locked_tarball(env: ManagedEnv, flake5: Path, nix: Nix) -> Path:
|
||||
return path
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def nonflake(env: ManagedEnv, request: pytest.FixtureRequest) -> Path:
|
||||
_init_files(nonflake_files, env.dirs.test_root, request.path.parent, env)
|
||||
return env.dirs.test_root / "nonFlake"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def registry(nix: Nix, flake1: Path, flake2: Path, flake3: Path) -> Path:
|
||||
registry = nix.env.dirs.test_root / "registry.json"
|
||||
@@ -432,6 +471,54 @@ class TestLock:
|
||||
assert "Added input 'flake1'" in logs
|
||||
assert f"fetching path input 'path:{flake5}" in logs
|
||||
|
||||
def test_override_inputs(
|
||||
self, nix: Nix, flake1: Path, flake3: Path, flake5_locked_tarball: Path, git: Git
|
||||
):
|
||||
# this is one big test due to necessary state changes, 🐻 with me
|
||||
flake1_original_commit = git(flake1, "rev-parse", "HEAD").stdout_s.strip()
|
||||
|
||||
url = f"file://{flake5_locked_tarball}"
|
||||
nix.nix(["flake", "lock", flake3, "--override-input", "flake2/flake1", url]).run().ok()
|
||||
lock = json.loads((flake3 / "flake.lock").read_text())
|
||||
assert lock["nodes"]["flake1"]["locked"]["url"] == url
|
||||
|
||||
nix.nix(["flake", "lock", flake3, "--override-input", "flake2/flake1", "flake1"]).run().ok()
|
||||
lock = json.loads((flake3 / "flake.lock").read_text())
|
||||
assert lock["nodes"]["flake1"]["locked"]["rev"] == flake1_original_commit
|
||||
|
||||
git(flake1, "checkout", "-b", "other")
|
||||
_modify_flake1(flake1, git)
|
||||
other_hash = git(flake1, "rev-parse", "HEAD").stdout_s.strip()
|
||||
git(flake1, "checkout", "main")
|
||||
|
||||
ref = f"flake1/other/{other_hash}"
|
||||
nix.nix(["flake", "lock", flake3, "--override-input", "flake2/flake1", ref]).run().ok()
|
||||
lock = json.loads((flake3 / "flake.lock").read_text())
|
||||
assert lock["nodes"]["flake1"]["locked"]["rev"] == other_hash
|
||||
|
||||
nix.nix(["flake", "lock", flake3]).run().ok()
|
||||
lock = json.loads((flake3 / "flake.lock").read_text())
|
||||
assert lock["nodes"]["flake1"]["locked"]["rev"] == other_hash
|
||||
|
||||
def test_update_individual_input(self, nix: Nix, flake1: Path, flake3_medium: Path, git: Git):
|
||||
flake1_original_commit = git(flake1, "rev-parse", "HEAD").stdout_s.strip()
|
||||
_modify_flake1(flake1, git)
|
||||
flake1_modified_commit = git(flake1, "rev-parse", "HEAD").stdout_s.strip()
|
||||
|
||||
nix.nix(["flake", "update", "flake2/flake1", "--flake", flake3_medium]).run().ok()
|
||||
lock = json.loads((flake3_medium / "flake.lock").read_text())
|
||||
assert lock["nodes"]["flake1"]["locked"]["rev"] == flake1_original_commit
|
||||
assert lock["nodes"]["flake1_2"]["locked"]["rev"] == flake1_modified_commit
|
||||
|
||||
def test_update_multiple_inputs(self, nix: Nix, flake1: Path, flake3_medium: Path, git: Git):
|
||||
_modify_flake1(flake1, git)
|
||||
flake1_modified_commit = git(flake1, "rev-parse", "HEAD").stdout_s.strip()
|
||||
|
||||
nix.nix(["flake", "update", "flake1", "flake2/flake1", "--flake", flake3_medium]).run().ok()
|
||||
lock = json.loads((flake3_medium / "flake.lock").read_text())
|
||||
assert lock["nodes"]["flake1"]["locked"]["rev"] == flake1_modified_commit
|
||||
assert lock["nodes"]["flake1_2"]["locked"]["rev"] == flake1_modified_commit
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("registry")
|
||||
class TestMetadata:
|
||||
|
||||
Reference in New Issue
Block a user