fetchurl: Introduce curlOptsList as an improvement over curlOpts

It's impossible to pass arguments with spaces with curlOpts.
curlOptsList supports that. Passing a list to curlOpts has been
deprecated. This commit is fully backwards compatible.
This commit is contained in:
Silvan Mosberger 2022-03-18 20:39:11 +01:00
parent ba558c6ce0
commit 86c902d673
2 changed files with 15 additions and 1 deletions

View File

@ -22,6 +22,8 @@ if ! [ -f "$SSL_CERT_FILE" ]; then
curl+=(--insecure)
fi
eval "curl+=($curlOptsList)"
curl+=(
$curlOpts
$NIX_CURL_FLAGS

View File

@ -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;