Merge pull request #35110 from oxij/pkgs/pretty-fetchurl

fetchurl: cleanup, better errors

authored by Michael Raskin and committed by GitHub e37b756b c10288c1

+23 -18
+18 -15
pkgs/build-support/fetchurl/default.nix
··· 1 - { stdenvNoCC, curl }: # Note that `curl' may be `null', in case of the native stdenvNoCC. 2 3 let 4 ··· 20 # "gnu", etc.). 21 sites = builtins.attrNames mirrors; 22 23 - impureEnvVars = stdenvNoCC.lib.fetchers.proxyImpureEnvVars ++ [ 24 # This variable allows the user to pass additional options to curl 25 "NIX_CURL_FLAGS" 26 ··· 89 , passthru ? {} 90 }: 91 92 - assert builtins.isList urls; 93 - assert (urls == []) != (url == ""); 94 assert sha512 != "" -> builtins.compareVersions "1.11" builtins.nixVersion <= 0; 95 96 97 - let 98 99 - hasHash = showURLs || (outputHash != "" && outputHashAlgo != "") 100 - || sha1 != "" || sha256 != "" || sha512 != ""; 101 - urls_ = if urls != [] then urls else [url]; 102 103 in 104 105 - if md5 != "" then throw "fetchurl does not support md5 anymore, please use sha256 or sha512" 106 - else if (!hasHash) then throw "Specify hash for fetchurl fixed-output derivation: ${stdenvNoCC.lib.concatStringsSep ", " urls_}" 107 - else stdenvNoCC.mkDerivation { 108 name = 109 if showURLs then "urls" 110 else if name != "" then name ··· 121 preferHashedMirrors = true; 122 123 # New-style output content requirements. 124 - outputHashAlgo = if outputHashAlgo != "" then outputHashAlgo else 125 - if sha512 != "" then "sha512" else if sha256 != "" then "sha256" else "sha1"; 126 - outputHash = if outputHash != "" then outputHash else 127 - if sha512 != "" then sha512 else if sha256 != "" then sha256 else sha1; 128 129 outputHashMode = if (recursiveHash || executable) then "recursive" else "flat"; 130
··· 1 + { lib, stdenvNoCC, curl }: # Note that `curl' may be `null', in case of the native stdenvNoCC. 2 3 let 4 ··· 20 # "gnu", etc.). 21 sites = builtins.attrNames mirrors; 22 23 + impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [ 24 # This variable allows the user to pass additional options to curl 25 "NIX_CURL_FLAGS" 26 ··· 89 , passthru ? {} 90 }: 91 92 assert sha512 != "" -> builtins.compareVersions "1.11" builtins.nixVersion <= 0; 93 94 + let 95 96 + urls_ = 97 + if urls != [] && url == "" then 98 + (if lib.isList urls then urls 99 + else throw "`urls` is not a list") 100 + else if urls == [] && url != "" then [url] 101 + else throw "fetchurl requires either `url` or `urls` to be set"; 102 103 + hash_ = 104 + if md5 != "" then throw "fetchurl does not support md5 anymore, please use sha256 or sha512" 105 + else if (outputHash != "" && outputHashAlgo != "") then { inherit outputHashAlgo outputHash; } 106 + else if sha512 != "" then { outputHashAlgo = "sha512"; outputHash = sha512; } 107 + else if sha256 != "" then { outputHashAlgo = "sha256"; outputHash = sha256; } 108 + else if sha1 != "" then { outputHashAlgo = "sha1"; outputHash = sha1; } 109 + else throw "fetchurl requires a hash for fixed-output derivation: ${lib.concatStringsSep ", " urls_}"; 110 111 in 112 113 + stdenvNoCC.mkDerivation { 114 name = 115 if showURLs then "urls" 116 else if name != "" then name ··· 127 preferHashedMirrors = true; 128 129 # New-style output content requirements. 130 + inherit (hash_) outputHashAlgo outputHash; 131 132 outputHashMode = if (recursiveHash || executable) then "recursive" else "flat"; 133
+1
pkgs/stdenv/darwin/default.nix
··· 118 initialPath = [ bootstrapTools ]; 119 120 fetchurlBoot = import ../../build-support/fetchurl { 121 stdenvNoCC = stage0.stdenv; 122 curl = bootstrapTools; 123 };
··· 118 initialPath = [ bootstrapTools ]; 119 120 fetchurlBoot = import ../../build-support/fetchurl { 121 + inherit lib; 122 stdenvNoCC = stage0.stdenv; 123 curl = bootstrapTools; 124 };
+2 -1
pkgs/stdenv/freebsd/default.nix
··· 29 inherit bootstrapTools; 30 31 fetchurl = import ../../build-support/fetchurl { 32 - inherit stdenv; 33 curl = bootstrapTools; 34 }; 35
··· 29 inherit bootstrapTools; 30 31 fetchurl = import ../../build-support/fetchurl { 32 + inherit lib; 33 + stdenvNoCC = stdenv; 34 curl = bootstrapTools; 35 }; 36
+1 -1
pkgs/stdenv/native/default.nix
··· 131 }; 132 133 fetchurl = import ../../build-support/fetchurl { 134 - inherit stdenv; 135 # Curl should be in /usr/bin or so. 136 curl = null; 137 };
··· 131 }; 132 133 fetchurl = import ../../build-support/fetchurl { 134 + inherit lib stdenvNoCC; 135 # Curl should be in /usr/bin or so. 136 curl = null; 137 };
+1 -1
pkgs/top-level/all-packages.nix
··· 195 196 # `fetchurl' downloads a file from the network. 197 fetchurl = import ../build-support/fetchurl { 198 - inherit stdenvNoCC; 199 # On darwin, libkrb5 needs bootstrap_cmds which would require 200 # converting many packages to fetchurl_boot to avoid evaluation cycles. 201 curl = buildPackages.curl.override (lib.optionalAttrs stdenv.isDarwin { gssSupport = false; });
··· 195 196 # `fetchurl' downloads a file from the network. 197 fetchurl = import ../build-support/fetchurl { 198 + inherit lib stdenvNoCC; 199 # On darwin, libkrb5 needs bootstrap_cmds which would require 200 # converting many packages to fetchurl_boot to avoid evaluation cycles. 201 curl = buildPackages.curl.override (lib.optionalAttrs stdenv.isDarwin { gssSupport = false; });