mirror of
https://github.com/NixOS/nix
synced 2025-06-25 06:31:14 +02:00
parent
a8e600e386
commit
a75b082a28
12 changed files with 159 additions and 163 deletions
|
@ -9,12 +9,12 @@ clearStore
|
|||
# Test fetching a flat file.
|
||||
hash=$(nix-hash --flat --type sha256 ./fetchurl.sh)
|
||||
|
||||
outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file://$(pwd)/fetchurl.sh --argstr sha256 $hash --no-out-link)
|
||||
outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url "file://$(pwd)/fetchurl.sh" --argstr sha256 "$hash" --no-out-link)
|
||||
|
||||
cmp $outPath fetchurl.sh
|
||||
cmp "$outPath" fetchurl.sh
|
||||
|
||||
# Do not re-fetch paths already present.
|
||||
outPath2=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file:///does-not-exist/must-remain-unused/fetchurl.sh --argstr sha256 $hash --no-out-link)
|
||||
outPath2=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file:///does-not-exist/must-remain-unused/fetchurl.sh --argstr sha256 "$hash" --no-out-link)
|
||||
test "$outPath" == "$outPath2"
|
||||
|
||||
# Now using a base-64 hash.
|
||||
|
@ -22,9 +22,9 @@ clearStore
|
|||
|
||||
hash=$(nix hash file --type sha512 --base64 ./fetchurl.sh)
|
||||
|
||||
outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file://$(pwd)/fetchurl.sh --argstr sha512 $hash --no-out-link)
|
||||
outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url "file://$(pwd)/fetchurl.sh" --argstr sha512 "$hash" --no-out-link)
|
||||
|
||||
cmp $outPath fetchurl.sh
|
||||
cmp "$outPath" fetchurl.sh
|
||||
|
||||
# Now using an SRI hash.
|
||||
clearStore
|
||||
|
@ -33,58 +33,58 @@ hash=$(nix hash file ./fetchurl.sh)
|
|||
|
||||
[[ $hash =~ ^sha256- ]]
|
||||
|
||||
outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file://$(pwd)/fetchurl.sh --argstr hash $hash --no-out-link)
|
||||
outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url "file://$(pwd)/fetchurl.sh" --argstr hash "$hash" --no-out-link)
|
||||
|
||||
cmp $outPath fetchurl.sh
|
||||
cmp "$outPath" fetchurl.sh
|
||||
|
||||
# Test that we can substitute from a different store dir.
|
||||
clearStore
|
||||
|
||||
other_store=file://$TEST_ROOT/other_store?store=/fnord/store
|
||||
other_store="file://$TEST_ROOT/other_store?store=/fnord/store"
|
||||
|
||||
hash=$(nix hash file --type sha256 --base16 ./fetchurl.sh)
|
||||
|
||||
storePath=$(nix --store $other_store store add-file ./fetchurl.sh)
|
||||
nix --store "$other_store" store add-file ./fetchurl.sh
|
||||
|
||||
outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr sha256 $hash --no-out-link --substituters $other_store)
|
||||
outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr sha256 "$hash" --no-out-link --substituters "$other_store")
|
||||
|
||||
# Test hashed mirrors with an SRI hash.
|
||||
nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr hash $(nix hash to-sri --type sha256 $hash) \
|
||||
--no-out-link --substituters $other_store
|
||||
nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file:///no-such-dir/fetchurl.sh --argstr hash "$(nix hash to-sri --type sha256 "$hash")" \
|
||||
--no-out-link --substituters "$other_store"
|
||||
|
||||
# Test unpacking a NAR.
|
||||
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
|
||||
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)
|
||||
hash=$(nix-hash --flat --type sha256 "$nar")
|
||||
|
||||
outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file://$nar --argstr sha256 $hash \
|
||||
outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url "file://$nar" --argstr sha256 "$hash" \
|
||||
--arg unpack true --argstr name xyzzy --no-out-link)
|
||||
|
||||
echo $outPath | grepQuiet 'xyzzy'
|
||||
echo "$outPath" | grepQuiet 'xyzzy'
|
||||
|
||||
test -x $outPath/fetchurl.sh
|
||||
test -L $outPath/symlink
|
||||
test -x "$outPath/fetchurl.sh"
|
||||
test -L "$outPath/symlink"
|
||||
|
||||
nix-store --delete $outPath
|
||||
nix-store --delete "$outPath"
|
||||
|
||||
# Test unpacking a compressed NAR.
|
||||
narxz=$TEST_ROOT/archive.nar.xz
|
||||
rm -f $narxz
|
||||
xz --keep $nar
|
||||
outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file://$narxz --argstr sha256 $hash \
|
||||
narxz="$TEST_ROOT/archive.nar.xz"
|
||||
rm -f "$narxz"
|
||||
xz --keep "$nar"
|
||||
outPath=$(nix-build -vvvvv --expr 'import <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
|
||||
test -x "$outPath/fetchurl.sh"
|
||||
test -L "$outPath/symlink"
|
||||
|
||||
# Make sure that *not* passing a outputHash fails.
|
||||
requireDaemonNewerThan "2.20"
|
||||
expected=100
|
||||
if [[ -v NIX_DAEMON_PACKAGE ]]; then expected=1; fi # work around the daemon not returning a 100 status correctly
|
||||
expectStderr $expected nix-build --expr '{ url }: builtins.derivation { name = "nix-cache-info"; system = "x86_64-linux"; builder = "builtin:fetchurl"; inherit url; outputHashMode = "flat"; }' --argstr url file://$narxz 2>&1 | grep 'must be a fixed-output or impure derivation'
|
||||
expectStderr $expected nix-build --expr '{ url }: builtins.derivation { name = "nix-cache-info"; system = "x86_64-linux"; builder = "builtin:fetchurl"; inherit url; outputHashMode = "flat"; }' --argstr url "file://$narxz" 2>&1 | grep 'must be a fixed-output or impure derivation'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue