`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
42 lines
1.1 KiB
Bash
42 lines
1.1 KiB
Bash
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\"; })"
|