2012-07-09 19:41:43 +00:00
|
|
|
source common.sh
|
|
|
|
|
|
|
|
clearStore
|
|
|
|
|
2015-10-30 11:33:40 +00:00
|
|
|
# Test fetching a flat file.
|
2015-10-30 10:27:47 +00:00
|
|
|
hash=$(nix-hash --flat --type sha256 ./fetchurl.sh)
|
2012-07-09 19:41:43 +00:00
|
|
|
|
2017-11-20 16:50:49 +00:00
|
|
|
outPath=$(nix-build '<nix/fetchurl.nix>' --argstr url file://$(pwd)/fetchurl.sh --argstr sha256 $hash --no-out-link --hashed-mirrors '')
|
2012-07-09 19:41:43 +00:00
|
|
|
|
2015-10-30 10:27:47 +00:00
|
|
|
cmp $outPath fetchurl.sh
|
|
|
|
|
2017-07-04 12:47:59 +00:00
|
|
|
# Now using a base-64 hash.
|
|
|
|
clearStore
|
|
|
|
|
|
|
|
hash=$(nix hash-file --type sha512 --base64 ./fetchurl.sh)
|
|
|
|
|
2017-11-20 16:50:49 +00:00
|
|
|
outPath=$(nix-build '<nix/fetchurl.nix>' --argstr url file://$(pwd)/fetchurl.sh --argstr sha512 $hash --no-out-link --hashed-mirrors '')
|
2017-07-04 12:47:59 +00:00
|
|
|
|
|
|
|
cmp $outPath fetchurl.sh
|
|
|
|
|
2018-12-13 13:30:52 +00:00
|
|
|
# Now using an SRI hash.
|
|
|
|
clearStore
|
|
|
|
|
|
|
|
hash=$(nix hash-file ./fetchurl.sh)
|
|
|
|
|
|
|
|
[[ $hash =~ ^sha512- ]]
|
|
|
|
|
|
|
|
outPath=$(nix-build '<nix/fetchurl.nix>' --argstr url file://$(pwd)/fetchurl.sh --argstr hash $hash --no-out-link --hashed-mirrors '')
|
|
|
|
|
|
|
|
cmp $outPath fetchurl.sh
|
|
|
|
|
2017-07-17 11:13:18 +00:00
|
|
|
# Test the hashed mirror feature.
|
|
|
|
clearStore
|
|
|
|
|
|
|
|
hash=$(nix hash-file --type sha512 --base64 ./fetchurl.sh)
|
|
|
|
hash32=$(nix hash-file --type sha512 --base16 ./fetchurl.sh)
|
|
|
|
|
|
|
|
mirror=$TMPDIR/hashed-mirror
|
|
|
|
rm -rf $mirror
|
|
|
|
mkdir -p $mirror/sha512
|
|
|
|
ln -s $(pwd)/fetchurl.sh $mirror/sha512/$hash32
|
|
|
|
|
2017-11-20 16:50:49 +00:00
|
|
|
outPath=$(nix-build '<nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr sha512 $hash --no-out-link --hashed-mirrors "file://$mirror")
|
2017-07-17 11:13:18 +00:00
|
|
|
|
2015-10-30 11:33:40 +00:00
|
|
|
# Test unpacking a NAR.
|
2015-10-30 10:27:47 +00: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 11:33:40 +00: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
|