From 3aed9c8dd4922ba60c27a097324708d2e47afedf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Mon, 19 May 2025 09:32:14 +0200 Subject: [PATCH] add tests for nix registry pin --- tests/functional/flakes/meson.build | 1 + tests/functional/flakes/registry-pin.sh | 58 +++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100755 tests/functional/flakes/registry-pin.sh diff --git a/tests/functional/flakes/meson.build b/tests/functional/flakes/meson.build index 213c388a6..1e22d66b9 100644 --- a/tests/functional/flakes/meson.build +++ b/tests/functional/flakes/meson.build @@ -3,6 +3,7 @@ suites += { 'deps': [], 'tests': [ 'flakes.sh', + 'registry-pin.sh', 'develop.sh', 'edit.sh', 'run.sh', diff --git a/tests/functional/flakes/registry-pin.sh b/tests/functional/flakes/registry-pin.sh new file mode 100755 index 000000000..cd96c6cba --- /dev/null +++ b/tests/functional/flakes/registry-pin.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash + +source ./common.sh + +TODO_NixOS + +requireGit + +clearStore +rm -rf "$TEST_HOME/.cache" "$TEST_HOME/.config" + +createFlake1 + +# Add a branch in flake1. +git -C "$flake1Dir" checkout -b branch1 +echo > "$flake1Dir/some-file" +git -C "$flake1Dir" add "$flake1Dir/some-file" +git -C "$flake1Dir" commit -m 'Some change' +git -C "$flake1Dir" checkout master + +nix registry add --registry "$registry" flake1 "git+file://$flake1Dir" + +commit=$(nix flake metadata "git+file://$flake1Dir" --json | jq -r '.revision') +commit2=$(nix flake metadata "git+file://$flake1Dir?ref=refs/heads/branch1" --json | jq -r '.revision') +[[ "$commit" != "$commit2" ]] + +nix registry list | grepQuiet '^global' # global flake1 + +commit=$(nix flake metadata flake1 --json | jq -r '.revision') +commit2=$(nix flake metadata flake1/branch1 --json | jq -r '.revision') +nix build -o "$TEST_ROOT/result" flake1#root +find "$TEST_ROOT/result/" | grepInverse some-file +nix build -o "$TEST_ROOT/result" flake1/branch1#root +find "$TEST_ROOT/result/" | grepQuiet some-file +[[ "$commit" != "$commit2" ]] + + +nix registry pin flake1 +# new output something like: +# user flake:flake1 git+file:///tmp/nix-test/flakes/registry-pin/flake1?ref=refs/heads/master&rev=c55c61f18fa23762b1dc700af6f33af012ec6772 +# global flake:flake1 git+file:///tmp/nix-test/flakes/registry-pin/flake1 +nix registry list | grepQuiet '^global' # global flake1 +nix registry list | grepQuiet '^user' # user flake1 +nix registry remove --registry "$registry" flake1 + +nix build -o "$TEST_ROOT/result" flake1#root +find "$TEST_ROOT/result/" | grepInverse some-file +nix build -o "$TEST_ROOT/result" flake1/branch1#root +find "$TEST_ROOT/result/" | grepQuiet some-file + +commit=$(nix flake metadata flake1 --json | jq -r '.revision') +# overriding the branch does still work +commit2=$(nix flake metadata flake1/branch1 --json | jq -r '.revision') +[[ "$commit" != "$commit2" ]] + +nix registry remove flake1 +nix registry list | grepInverse '^user' # no more pinned flake1 +nix registry list | grepQuiet '^global' # global flake1 is still there