Merge pull request #164662 from infinisil/fetchurl-curlOpts-list

fetchurl: Allow passing curl options with spaces

authored by Robert Hensing and committed by GitHub 1e17bb94 ff3d914a

+30 -2
+2
pkgs/build-support/fetchurl/builder.sh
··· 22 22 curl+=(--insecure) 23 23 fi 24 24 25 + eval "curl+=($curlOptsList)" 26 + 25 27 curl+=( 26 28 $curlOpts 27 29 $NIX_CURL_FLAGS
+13 -1
pkgs/build-support/fetchurl/default.nix
··· 46 46 urls ? [] 47 47 48 48 , # Additional curl options needed for the download to succeed. 49 + # Warning: Each space (no matter the escaping) will start a new argument. 50 + # If you wish to pass arguments with spaces, use `curlOptsList` 49 51 curlOpts ? "" 52 + 53 + , # Additional curl options needed for the download to succeed. 54 + curlOptsList ? [] 50 55 51 56 , # Name of the file. If empty, use the basename of `url' (or of the 52 57 # first element of `urls'). ··· 147 152 148 153 outputHashMode = if (recursiveHash || executable) then "recursive" else "flat"; 149 154 150 - inherit curlOpts showURLs mirrorsFile postFetch downloadToTemp executable; 155 + curlOpts = lib.warnIf (lib.isList curlOpts) '' 156 + fetchurl for ${toString (builtins.head urls_)}: curlOpts is a list (${lib.generators.toPretty { multiline = false; } curlOpts}), which is not supported anymore. 157 + - 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: 158 + curlOpts = ${lib.strings.escapeNixString (toString curlOpts)}; 159 + - If you wish for each list element to be passed as a separate curl argument, allowing arguments to contain spaces, use curlOptsList instead: 160 + curlOptsList = [ ${lib.concatMapStringsSep " " lib.strings.escapeNixString curlOpts} ];'' curlOpts; 161 + curlOptsList = lib.escapeShellArgs curlOptsList; 162 + inherit showURLs mirrorsFile postFetch downloadToTemp executable; 151 163 152 164 impureEnvVars = impureEnvVars ++ netrcImpureEnvVars; 153 165
+13
pkgs/build-support/fetchurl/tests.nix
··· 1 + { invalidateFetcherByDrvHash, fetchurl, jq, moreutils, ... }: { 2 + # Tests that we can send custom headers with spaces in them 3 + header = 4 + let headerValue = "Test '\" <- These are some quotes"; 5 + in invalidateFetcherByDrvHash fetchurl { 6 + url = "https://httpbin.org/headers"; 7 + sha256 = builtins.hashString "sha256" (headerValue + "\n"); 8 + curlOptsList = [ "-H" "Hello: ${headerValue}" ]; 9 + postFetch = '' 10 + ${jq}/bin/jq -r '.headers.Hello' $out | ${moreutils}/bin/sponge $out 11 + ''; 12 + }; 13 + }
+1 -1
pkgs/games/factorio/default.nix
··· 85 85 (lib.overrideDerivation 86 86 (fetchurl { 87 87 inherit name url sha256; 88 - curlOpts = [ 88 + curlOptsList = [ 89 89 "--get" 90 90 "--data-urlencode" "username@username" 91 91 "--data-urlencode" "token@token"
+1
pkgs/test/default.nix
··· 29 29 cc-multilib-gcc = callPackage ./cc-wrapper/multilib.nix { stdenv = gccMultiStdenv; }; 30 30 cc-multilib-clang = callPackage ./cc-wrapper/multilib.nix { stdenv = clangMultiStdenv; }; 31 31 32 + fetchurl = callPackages ../build-support/fetchurl/tests.nix { }; 32 33 fetchpatch = callPackages ../build-support/fetchpatch/tests.nix { }; 33 34 fetchzip = callPackages ../build-support/fetchzip/tests.nix { }; 34 35 fetchgit = callPackages ../build-support/fetchgit/tests.nix { };