Files
Tom Hubrecht e468102508 fix: Consider fetchGit locked when narHash is present
`fetchGit` has been modified a long time ago to use fetchTree, however,
we don't care about `lastModified` because we are not in a flake
context, this hack introduces a `git-locked` type of input that only
cares about `narHash` being present. This is needed to avoid fetching
the remote repo each time `fetchGit` is evaluated whith the result
present in the store.

Change-Id: I521c6fcccf8cf12945594f205d7fd4c8c2cf89e9
2025-05-28 22:24:23 +00:00

42 lines
1.1 KiB
Bash
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
source common.sh
requireGit
clearStore
# Intentionally not in a canonical form
# See https://github.com/NixOS/nix/issues/6195
repo=$TEST_ROOT/./git
export _NIX_FORCE_HTTP=1
rm -rf "$repo" "$TEST_HOME/.cache/nix"
mkdir "$repo" && pushd "$repo"
git init --initial-branch=main
git config user.email "foobar@example.com"
git config user.name "Foobar"
echo utrecht >hello
touch .gitignore
git add hello .gitignore
git commit -m 'Bla1'
rev1=$(git rev-parse HEAD)
git tag -a tag1 -m tag1
# Compute the hash of the output
path=$(nix eval --impure --raw --expr "(builtins.fetchGit \"file://$repo\").outPath")
hash=$(nix-hash --type sha256 --base32 "$path")
narHash=$(nix-hash --to-sri --type sha256 "$hash")
# Remove the repo, and the local cache
popd && rm -rf "$repo" "$TEST_HOME/.cache/nix"
# The path is locked and can be fetched
path2=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repo\"; ref = \"main\"; rev=\"$rev1\"; narHash = \"$narHash\"; })")
[[ "$path" = "$path2" ]]
# When no narHash is present the fetching fails
! nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repo\"; ref = \"main\"; rev=\"$rev1\"; })"