diff --git a/pkgs/build-support/fetchurl/builder.sh b/pkgs/build-support/fetchurl/builder.sh index 5b04a702aff4..5ca09b6fc77d 100644 --- a/pkgs/build-support/fetchurl/builder.sh +++ b/pkgs/build-support/fetchurl/builder.sh @@ -22,6 +22,8 @@ if ! [ -f "$SSL_CERT_FILE" ]; then curl+=(--insecure) fi +eval "curl+=($curlOptsList)" + curl+=( $curlOpts $NIX_CURL_FLAGS diff --git a/pkgs/build-support/fetchurl/default.nix b/pkgs/build-support/fetchurl/default.nix index 776089dab999..2e5fa9162926 100644 --- a/pkgs/build-support/fetchurl/default.nix +++ b/pkgs/build-support/fetchurl/default.nix @@ -45,8 +45,13 @@ in urls ? [] , # Additional curl options needed for the download to succeed. + # Warning: Each space (no matter the escaping) will start a new argument. + # If you wish to pass arguments with spaces, use `curlOptsList` curlOpts ? "" +, # Additional curl options needed for the download to succeed. + curlOptsList ? [] + , # Name of the file. If empty, use the basename of `url' (or of the # first element of `urls'). name ? "" @@ -148,7 +153,14 @@ stdenvNoCC.mkDerivation { outputHashMode = if (recursiveHash || executable) then "recursive" else "flat"; - inherit curlOpts showURLs mirrorsFile postFetch downloadToTemp executable; + curlOpts = lib.warnIf (lib.isList curlOpts) '' + fetchurl for ${toString (builtins.head urls_)}: curlOpts is a list (${lib.generators.toPretty { multiline = false; } curlOpts}), which is not supported anymore. + - If you wish to get the same effect as before, for elements with spaces (even if escaped) to expand to multiple curl arguments, use a string argument instead: + curlOpts = ${lib.strings.escapeNixString (toString curlOpts)}; + - If you wish for each list element to be passed as a separate curl argument, allowing arguments to contain spaces, use curlOptsList instead: + curlOptsList = [ ${lib.concatMapStringsSep " " lib.strings.escapeNixString curlOpts} ];'' curlOpts; + curlOptsList = lib.escapeShellArgs curlOptsList; + inherit showURLs mirrorsFile postFetch downloadToTemp executable; impureEnvVars = impureEnvVars ++ netrcImpureEnvVars;