2022-03-22 22:19:21 +00:00
source common.sh
2022-03-24 20:33:20 +00:00
enableFeatures "fetch-closure"
2022-03-22 22:19:21 +00:00
clearStore
clearCacheCache
2023-05-24 13:35:46 +00:00
# Old daemons don't properly zero out the self-references when
# calculating the CA hashes, so this breaks `nix store
# make-content-addressed` which expects the client and the daemon to
# compute the same hash
requireDaemonNewerThan "2.16.0pre20230524"
2022-03-22 22:19:21 +00:00
# Initialize binary cache.
2022-05-02 07:38:51 +00:00
nonCaPath = $( nix build --json --file ./dependencies.nix --no-link | jq -r .[ ] .outputs.out)
2022-03-22 22:19:21 +00:00
caPath = $( nix store make-content-addressed --json $nonCaPath | jq -r '.rewrites | map(.) | .[]' )
nix copy --to file://$cacheDir $nonCaPath
# Test basic fetchClosure rewriting from non-CA to CA.
clearStore
[ ! -e $nonCaPath ]
[ ! -e $caPath ]
[ [ $( nix eval -v --raw --expr "
builtins.fetchClosure {
fromStore = \" file://$cacheDir \" ;
fromPath = $nonCaPath ;
toPath = $caPath ;
}
" ) = $caPath ]]
[ ! -e $nonCaPath ]
[ -e $caPath ]
2022-12-01 15:29:09 +00:00
if [ [ " $NIX_REMOTE " != "daemon" ] ] ; then
2023-05-19 08:48:53 +00:00
# We can use non-CA paths when we ask explicitly.
[ [ $( nix eval --raw --no-require-sigs --expr "
2022-12-01 15:29:09 +00:00
builtins.fetchClosure {
fromStore = \" file://$cacheDir \" ;
fromPath = $nonCaPath ;
2023-05-19 08:48:53 +00:00
inputAddressed = true;
2022-12-01 15:29:09 +00:00
}
" ) = $nonCaPath ]]
[ -e $nonCaPath ]
2022-03-22 22:19:21 +00:00
2023-05-19 08:48:53 +00:00
# .. but only if we ask explicitly.
expectStderr 1 nix eval --raw --no-require-sigs --expr "
builtins.fetchClosure {
fromStore = \" file://$cacheDir \" ;
fromPath = $nonCaPath ;
}
" | grepQuiet -E " The .fromPath. value .* is input addressed, but input addressing was not requested. If you do intend to return an input addressed store path, add .inputAddressed = true; . to the .fetchClosure. arguments."
[ -e $nonCaPath ]
2022-12-01 15:29:09 +00:00
fi
2022-03-22 22:19:21 +00:00
# 'toPath' set to empty string should fail but print the expected path.
2021-12-09 15:26:46 +00:00
expectStderr 1 nix eval -v --json --expr "
2022-03-22 22:19:21 +00:00
builtins.fetchClosure {
fromStore = \" file://$cacheDir \" ;
fromPath = $nonCaPath ;
toPath = \" \" ;
}
2021-12-09 15:26:46 +00:00
" | grep " error: rewriting.*$nonCaPath .*yielded.*$caPath "
2022-03-22 22:19:21 +00:00
# If fromPath is CA, then toPath isn't needed.
nix copy --to file://$cacheDir $caPath
[ [ $( nix eval -v --raw --expr "
builtins.fetchClosure {
fromStore = \" file://$cacheDir \" ;
fromPath = $caPath ;
}
" ) = $caPath ]]
2022-04-06 09:52:51 +00:00
# Check that URL query parameters aren't allowed.
clearStore
narCache = $TEST_ROOT /nar-cache
rm -rf $narCache
( ! nix eval -v --raw --expr "
builtins.fetchClosure {
fromStore = \" file://$cacheDir ?local-nar-cache= $narCache \" ;
fromPath = $caPath ;
}
" )
( ! [ -e $narCache ] )