summary refs log tree commit diff
path: root/pkgs/build-support/fetchurl/builder.sh
diff options
context:
space:
mode:
authorDaniel Peebles <copumpkin@users.noreply.github.com>2018-06-11 12:49:06 -0400
committerGitHub <noreply@github.com>2018-06-11 12:49:06 -0400
commit363363298c95e83c268f3a80c117818169954389 (patch)
tree25946add48bf3936fb115566b1900edc2e5ba9a7 /pkgs/build-support/fetchurl/builder.sh
parentf550fa4a72951346493666fea7171732496d2d7f (diff)
parentf44012ba10537e1a2a94b2be443a86e4dd0ad38f (diff)
downloadnixlib-363363298c95e83c268f3a80c117818169954389.tar
nixlib-363363298c95e83c268f3a80c117818169954389.tar.gz
nixlib-363363298c95e83c268f3a80c117818169954389.tar.bz2
nixlib-363363298c95e83c268f3a80c117818169954389.tar.lz
nixlib-363363298c95e83c268f3a80c117818169954389.tar.xz
nixlib-363363298c95e83c268f3a80c117818169954389.tar.zst
nixlib-363363298c95e83c268f3a80c117818169954389.zip
Merge pull request #17757 from copumpkin/fetchurl-user-agent
fetchurl: add user agent
Diffstat (limited to 'pkgs/build-support/fetchurl/builder.sh')
-rw-r--r--pkgs/build-support/fetchurl/builder.sh26
1 files changed, 15 insertions, 11 deletions
diff --git a/pkgs/build-support/fetchurl/builder.sh b/pkgs/build-support/fetchurl/builder.sh
index 7c2bdf260b4e..f9bc8b602f4c 100644
--- a/pkgs/build-support/fetchurl/builder.sh
+++ b/pkgs/build-support/fetchurl/builder.sh
@@ -2,20 +2,24 @@ source $stdenv/setup
 
 source $mirrorsFile
 
+curlVersion=$(curl -V | head -1 | cut -d' ' -f2)
 
 # 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).
-curl="curl \
- --location --max-redirs 20 \
- --retry 3 \
- --disable-epsv \
- --cookie-jar cookies \
- --insecure \
- $curlOpts \
- $NIX_CURL_FLAGS"
-
+curl=(
+    curl
+    --location
+    --max-redirs 20
+    --retry 3
+    --disable-epsv
+    --cookie-jar cookies
+    --insecure
+    --user-agent "curl/$curlVersion Nixpkgs/$nixpkgsVersion"
+    $curlOpts
+    $NIX_CURL_FLAGS
+)
 
 downloadedFile="$out"
 if [ -n "$downloadToTemp" ]; then downloadedFile="$TMPDIR/file"; fi
@@ -32,7 +36,7 @@ tryDownload() {
     # 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 - --fail "$url" --output "$downloadedFile"; then
+       if "${curl[@]}" -C - --fail "$url" --output "$downloadedFile"; then
           success=1
           break
        else
@@ -61,7 +65,7 @@ tryHashedMirrors() {
 
     for mirror in $hashedMirrors; do
         url="$mirror/$outputHashAlgo/$outputHash"
-        if $curl --retry 0 --connect-timeout "${NIX_CONNECT_TIMEOUT:-15}" \
+        if "${curl[@]}" --retry 0 --connect-timeout "${NIX_CONNECT_TIMEOUT:-15}" \
             --fail --silent --show-error --head "$url" \
             --write-out "%{http_code}" --output /dev/null > code 2> log; then
             tryDownload "$url"