nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 81 lines 2.1 kB view raw
1#! /bin/sh -e 2 3url=$1 4rev=$2 5expHash=$3 6 7hashType=$NIX_HASH_ALGO 8if test -z "$hashType"; then 9 hashType=sha256 10fi 11if test -z "$hashFormat"; then 12 hashFormat=--base32 13fi 14 15if test -z "$url"; then 16 echo "syntax: nix-prefetch-svn URL [REVISION [EXPECTED-HASH]]" >&2 17 exit 1 18fi 19 20test -n "$rev" || rev="HEAD" 21 22repoName=$(echo $url | sed ' 23 s,.*/\([^/]\+\)/trunk/*$,\1,;t 24 s,.*/\([^/]\+\)/branches/\([^/]\+\)/*$,\1-\2,;t 25 s,.*/\([^/]\+\)/tags/\([^/]\+\)/*$,\1-\2,;t 26 s,.*/\([^/]\+\)/*$,\1,;t 27') 28dstFile=$repoName-r$rev 29 30# If the hash was given, a file with that hash may already be in the 31# store. 32if test -n "$expHash"; then 33 finalPath=$(nix-store --print-fixed-path --recursive "$hashType" "$expHash" $dstFile) 34 if ! nix-store --check-validity "$finalPath" 2> /dev/null; then 35 finalPath= 36 fi 37 hash=$expHash 38fi 39 40 41# If we don't know the hash or a path with that hash doesn't exist, 42# download the file and add it to the store. 43if test -z "$finalPath"; then 44 # nix>=2.20 rejects adding symlinked paths to the store, so use realpath 45 # to resolve to a physical path. https://github.com/NixOS/nix/issues/11941 46 tmpPath="$(realpath "$(mktemp -d --tmpdir svn-checkout-tmp-XXXXXXXX)")" 47 trap "rm -rf \"$tmpPath\"" EXIT 48 49 tmpFile="$tmpPath/$dstFile" 50 51 # Perform the checkout. 52 if test "$NIX_PREFETCH_SVN_LEAVE_DOT_SVN" != 1 53 then 54 command="export" 55 else 56 command="checkout" 57 fi 58 59 echo p | svn "$command" --quiet -r "$rev" "$url" "$tmpFile" >&2 60 echo "svn revision is $(svn info -r "$rev" "$url" | grep "Revision: " | cut -d' ' -f2)" 61 62 # Compute the hash. 63 hash=$(nix-hash --type $hashType $hashFormat $tmpFile) 64 if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi 65 66 # Add the downloaded file to the Nix store. 67 finalPath=$(nix-store --add-fixed --recursive "$hashType" $tmpFile) 68 69 if test -n "$expHash" -a "$expHash" != "$hash"; then 70 echo "hash mismatch for URL \`$url'" 71 exit 1 72 fi 73fi 74 75if ! test -n "$QUIET"; then echo "path is $finalPath" >&2; fi 76 77echo $hash 78 79if test -n "$PRINT_PATH"; then 80 echo $finalPath 81fi