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