mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 23:13:19 +00:00
8bc5104a6e
When specifying the `builder` attribute in `stdenv.mkDerivation`, this will be effectively transformed into builtins.derivation { builder = stdenv.shell; args = [ "-e" builder ]; } This also means that `default-builder.sh` is never sourced and as a result it's not guaranteed that `$NIX_ATTRS_SH_FILE` is set to a correct location[1]. Also, we need to source `.attrs.sh` to source `$stdenv`. So, the following is done now: * If `$NIX_ATTRS_SH_FILE` points to a correct location, then use it. Directly using `.attrs.sh` is problematic for `nix-shell(1)` usage (see previous commit for more context), so prefer the environment variable if possible. * Otherwise, if `.attrs.sh` exists, then use it. See [1] for when this can happen. * If neither applies, it can be assumed that `__structuredAttrs` is turned off and thus nothing needs to be done. [1] It's possible that it doesn't exist at all - in case of Nix 2.3 or it can point to a wrong location on older Nix versions with a bug in `__structuredAttrs`.
89 lines
2.4 KiB
Bash
89 lines
2.4 KiB
Bash
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
|
||
source $stdenv/setup
|
||
|
||
# Curl flags to handle redirects, not use EPSV, handle cookies for
|
||
# servers to need them during redirects, and work on SSL without a
|
||
# certificate (this isn't a security problem because we check the
|
||
# cryptographic hash of the output anyway).
|
||
|
||
set -o noglob
|
||
|
||
curl="curl \
|
||
--location \
|
||
--max-redirs 20 \
|
||
--retry 2 \
|
||
--disable-epsv \
|
||
--cookie-jar cookies \
|
||
--insecure \
|
||
--speed-time 5 \
|
||
-# \
|
||
--fail \
|
||
$curlOpts \
|
||
$NIX_CURL_FLAGS"
|
||
|
||
finish() {
|
||
runHook postFetch
|
||
set +o noglob
|
||
exit 0
|
||
}
|
||
|
||
ipfs_add() {
|
||
if curl --retry 0 --head --silent "localhost:5001" > /dev/null; then
|
||
echo "[0m[01;36m=IPFS=[0m add $ipfs"
|
||
tar --owner=root --group=root -cWf "source.tar" $(echo *)
|
||
res=$(curl -# -F "file=@source.tar" "localhost:5001/api/v0/tar/add" | sed 's/.*"Hash":"\(.*\)".*/\1/')
|
||
if [ $ipfs != $res ]; then
|
||
echo "\`ipfs tar add' results in $res when $ipfs is expected"
|
||
exit 1
|
||
fi
|
||
rm "source.tar"
|
||
fi
|
||
}
|
||
|
||
echo
|
||
|
||
mkdir download
|
||
cd download
|
||
|
||
if curl --retry 0 --head --silent "localhost:5001" > /dev/null; then
|
||
curlexit=18;
|
||
echo "[0m[01;36m=IPFS=[0m get $ipfs"
|
||
# if we get error code 18, resume partial download
|
||
while [ $curlexit -eq 18 ]; do
|
||
# keep this inside an if statement, since on failure it doesn't abort the script
|
||
if $curl -C - "http://localhost:5001/api/v0/tar/cat?arg=$ipfs" --output "$ipfs.tar"; then
|
||
unpackFile "$ipfs.tar"
|
||
rm "$ipfs.tar"
|
||
set +o noglob
|
||
mv $(echo *) "$out"
|
||
finish
|
||
else
|
||
curlexit=$?;
|
||
fi
|
||
done
|
||
fi
|
||
|
||
if test -n "$url"; then
|
||
curlexit=18;
|
||
echo "Downloading $url"
|
||
while [ $curlexit -eq 18 ]; do
|
||
# keep this inside an if statement, since on failure it doesn't abort the script
|
||
if $curl "$url" -O; then
|
||
set +o noglob
|
||
tmpfile=$(echo *)
|
||
unpackFile $tmpfile
|
||
rm $tmpfile
|
||
ipfs_add
|
||
mv $(echo *) "$out"
|
||
finish
|
||
else
|
||
curlexit=$?;
|
||
fi
|
||
done
|
||
fi
|
||
|
||
echo "[01;31merror:[0m cannot download $ipfs from ipfs or the given url"
|
||
echo
|
||
set +o noglob
|
||
exit 1
|