git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #17757 from copumpkin/fetchurl-user-agent

fetchurl: add user agent

commit363363298c95e83c268f3a80c117818169954389 authorDaniel Peebles <copumpkin@users.noreply.github.com> dateMon 11 Jun 2018, 12:49 (8 years ago) parentf550fa4f44012b
2 files changed+17−13
pkgs/build-support/fetchurl/builder.sh+15−11 pkgs/build-support/fetchurl/default.nix+2−2
pkgs/build-support/fetchurl/builder.sh+15−11
@@ -2,20 +2,24 @@ source $stdenv/setup
22
33source $mirrorsFile
44
5+curlVersion=$(curl -V | head -1 | cut -d' ' -f2)
56
67# Curl flags to handle redirects, not use EPSV, handle cookies for
78# servers to need them during redirects, and work on SSL without a
89# certificate (this isn't a security problem because we check the
910# cryptographic hash of the output anyway).
10−curl="curl \
11− --location --max-redirs 20 \
12− --retry 3 \
13− --disable-epsv \
14− --cookie-jar cookies \
15− --insecure \
16− $curlOpts \
17− $NIX_CURL_FLAGS"
18−
11+curl=(
12+ curl
13+ --location
14+ --max-redirs 20
15+ --retry 3
16+ --disable-epsv
17+ --cookie-jar cookies
18+ --insecure
19+ --user-agent "curl/$curlVersion Nixpkgs/$nixpkgsVersion"
20+ $curlOpts
21+ $NIX_CURL_FLAGS
22+)
1923
2024downloadedFile="$out"
2125if [ -n "$downloadToTemp" ]; then downloadedFile="$TMPDIR/file"; fi
@@ -32,7 +36,7 @@ tryDownload() {
3236 # if we get error code 18, resume partial download
3337 while [ $curlexit -eq 18 ]; do
3438 # keep this inside an if statement, since on failure it doesn't abort the script
35− if $curl -C - --fail "$url" --output "$downloadedFile"; then
39+ if "${curl[@]}" -C - --fail "$url" --output "$downloadedFile"; then
3640 success=1
3741 break
3842 else
@@ -61,7 +65,7 @@ tryHashedMirrors() {
6165
6266 for mirror in $hashedMirrors; do
6367 url="$mirror/$outputHashAlgo/$outputHash"
64− if $curl --retry 0 --connect-timeout "${NIX_CONNECT_TIMEOUT:-15}" \
68+ if "${curl[@]}" --retry 0 --connect-timeout "${NIX_CONNECT_TIMEOUT:-15}" \
6569 --fail --silent --show-error --head "$url" \
6670 --write-out "%{http_code}" --output /dev/null > code 2> log; then
6771 tryDownload "$url"
pkgs/build-support/fetchurl/default.nix+2−2
@@ -92,7 +92,6 @@ in
9292assert sha512 != "" -> builtins.compareVersions "1.11" builtins.nixVersion <= 0;
9393
9494let
95−
9695 urls_ =
9796 if urls != [] && url == "" then
9897 (if lib.isList urls then urls
@@ -107,7 +106,6 @@ let
107106 else if sha256 != "" then { outputHashAlgo = "sha256"; outputHash = sha256; }
108107 else if sha1 != "" then { outputHashAlgo = "sha1"; outputHash = sha1; }
109108 else throw "fetchurl requires a hash for fixed-output derivation: ${lib.concatStringsSep ", " urls_}";
110−
111109in
112110
113111stdenvNoCC.mkDerivation {
@@ -135,6 +133,8 @@ stdenvNoCC.mkDerivation {
135133
136134 impureEnvVars = impureEnvVars ++ netrcImpureEnvVars;
137135
136+ nixpkgsVersion = lib.trivial.release;
137+
138138 # Doing the download on a remote machine just duplicates network
139139 # traffic, so don't do that.
140140 preferLocalBuild = true;