2012-07-09 21:41:43 +02:00
|
|
|
source common.sh
|
|
|
|
|
|
|
|
clearStore
|
|
|
|
|
2015-10-30 12:33:40 +01:00
|
|
|
# Test fetching a flat file.
|
2015-10-30 11:27:47 +01:00
|
|
|
hash=$(nix-hash --flat --type sha256 ./fetchurl.sh)
|
2012-07-09 21:41:43 +02:00
|
|
|
|
2020-06-12 21:39:44 +02:00
|
|
|
outPath=$(nix-build '<nix/fetchurl.nix>' --argstr url file://$(pwd)/fetchurl.sh --argstr sha256 $hash --no-out-link)
|
2012-07-09 21:41:43 +02:00
|
|
|
|
2015-10-30 11:27:47 +01:00
|
|
|
cmp $outPath fetchurl.sh
|
|
|
|
|
2017-07-04 14:47:59 +02:00
|
|
|
# Now using a base-64 hash.
|
|
|
|
clearStore
|
|
|
|
|
2020-07-24 18:44:43 +02:00
|
|
|
hash=$(nix hash file --type sha512 --base64 ./fetchurl.sh)
|
2017-07-04 14:47:59 +02:00
|
|
|
|
2020-06-12 21:39:44 +02:00
|
|
|
outPath=$(nix-build '<nix/fetchurl.nix>' --argstr url file://$(pwd)/fetchurl.sh --argstr sha512 $hash --no-out-link)
|
2017-07-04 14:47:59 +02:00
|
|
|
|
|
|
|
cmp $outPath fetchurl.sh
|
|
|
|
|
2018-12-13 14:30:52 +01:00
|
|
|
# Now using an SRI hash.
|
|
|
|
clearStore
|
|
|
|
|
2020-07-24 18:44:43 +02:00
|
|
|
hash=$(nix hash file ./fetchurl.sh)
|
2018-12-13 14:30:52 +01:00
|
|
|
|
2018-12-15 05:37:20 +01:00
|
|
|
[[ $hash =~ ^sha256- ]]
|
2018-12-13 14:30:52 +01:00
|
|
|
|
2020-06-12 21:39:44 +02:00
|
|
|
outPath=$(nix-build '<nix/fetchurl.nix>' --argstr url file://$(pwd)/fetchurl.sh --argstr hash $hash --no-out-link)
|
2018-12-13 14:30:52 +01:00
|
|
|
|
|
|
|
cmp $outPath fetchurl.sh
|
|
|
|
|
2020-06-12 21:39:44 +02:00
|
|
|
# Test that we can substitute from a different store dir.
|
2017-07-17 13:13:18 +02:00
|
|
|
clearStore
|
|
|
|
|
2020-06-13 07:07:42 +02:00
|
|
|
other_store=file://$TEST_ROOT/other_store?store=/fnord/store
|
2017-07-17 13:13:18 +02:00
|
|
|
|
2020-07-24 18:44:43 +02:00
|
|
|
hash=$(nix hash file --type sha256 --base16 ./fetchurl.sh)
|
2017-07-17 13:13:18 +02:00
|
|
|
|
2020-06-12 22:32:52 +02:00
|
|
|
storePath=$(nix --store $other_store add-to-store --flat ./fetchurl.sh)
|
|
|
|
|
2020-06-13 07:14:30 +02:00
|
|
|
outPath=$(nix-build '<nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr sha256 $hash --no-out-link --substituters $other_store)
|
2017-07-17 13:13:18 +02:00
|
|
|
|
2019-06-01 15:27:43 +02:00
|
|
|
# Test hashed mirrors with an SRI hash.
|
2020-07-24 18:44:43 +02:00
|
|
|
nix-build '<nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr hash $(nix hash to-sri --type sha256 $hash) \
|
2020-06-12 22:33:24 +02:00
|
|
|
--no-out-link --substituters $other_store
|
2019-06-01 15:27:43 +02:00
|
|
|
|
2015-10-30 12:33:40 +01:00
|
|
|
# Test unpacking a NAR.
|
2015-10-30 11:27:47 +01:00
|
|
|
rm -rf $TEST_ROOT/archive
|
|
|
|
mkdir -p $TEST_ROOT/archive
|
|
|
|
cp ./fetchurl.sh $TEST_ROOT/archive
|
|
|
|
chmod +x $TEST_ROOT/archive/fetchurl.sh
|
|
|
|
ln -s foo $TEST_ROOT/archive/symlink
|
|
|
|
nar=$TEST_ROOT/archive.nar
|
|
|
|
nix-store --dump $TEST_ROOT/archive > $nar
|
|
|
|
|
|
|
|
hash=$(nix-hash --flat --type sha256 $nar)
|
|
|
|
|
|
|
|
outPath=$(nix-build '<nix/fetchurl.nix>' --argstr url file://$nar --argstr sha256 $hash \
|
|
|
|
--arg unpack true --argstr name xyzzy --no-out-link)
|
|
|
|
|
|
|
|
echo $outPath | grep -q 'xyzzy'
|
|
|
|
|
|
|
|
test -x $outPath/fetchurl.sh
|
|
|
|
test -L $outPath/symlink
|
2015-10-30 12:33:40 +01:00
|
|
|
|
|
|
|
nix-store --delete $outPath
|
|
|
|
|
|
|
|
# Test unpacking a compressed NAR.
|
|
|
|
narxz=$TEST_ROOT/archive.nar.xz
|
|
|
|
rm -f $narxz
|
|
|
|
xz --keep $nar
|
|
|
|
outPath=$(nix-build '<nix/fetchurl.nix>' --argstr url file://$narxz --argstr sha256 $hash \
|
|
|
|
--arg unpack true --argstr name xyzzy --no-out-link)
|
|
|
|
|
|
|
|
test -x $outPath/fetchurl.sh
|
|
|
|
test -L $outPath/symlink
|