fetchurl: cleanup, better errors

Also fix what seems like bugs in uncommon `stdenv`s.
This commit is contained in:
Jan Malakhovski 2018-02-17 18:44:43 +00:00
parent ecf4825f32
commit a89899ce4e
5 changed files with 23 additions and 18 deletions

View File

@ -1,4 +1,4 @@
{ stdenvNoCC, curl }: # Note that `curl' may be `null', in case of the native stdenvNoCC. { lib, stdenvNoCC, curl }: # Note that `curl' may be `null', in case of the native stdenvNoCC.
let let
@ -20,7 +20,7 @@ let
# "gnu", etc.). # "gnu", etc.).
sites = builtins.attrNames mirrors; sites = builtins.attrNames mirrors;
impureEnvVars = stdenvNoCC.lib.fetchers.proxyImpureEnvVars ++ [ impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [
# This variable allows the user to pass additional options to curl # This variable allows the user to pass additional options to curl
"NIX_CURL_FLAGS" "NIX_CURL_FLAGS"
@ -89,22 +89,28 @@ in
, passthru ? {} , passthru ? {}
}: }:
assert builtins.isList urls;
assert (urls == []) != (url == "");
assert sha512 != "" -> builtins.compareVersions "1.11" builtins.nixVersion <= 0; assert sha512 != "" -> builtins.compareVersions "1.11" builtins.nixVersion <= 0;
let let
hasHash = showURLs || (outputHash != "" && outputHashAlgo != "") urls_ =
|| sha1 != "" || sha256 != "" || sha512 != ""; if urls != [] && url == "" then
urls_ = if urls != [] then urls else [url]; (if lib.isList urls then urls
else throw "`urls` is not a list")
else if urls == [] && url != "" then [url]
else throw "fetchurl requires either `url` or `urls` to be set";
hash_ =
if md5 != "" then throw "fetchurl does not support md5 anymore, please use sha256 or sha512"
else if (outputHash != "" && outputHashAlgo != "") then { inherit outputHashAlgo outputHash; }
else if sha512 != "" then { outputHashAlgo = "sha512"; outputHash = sha512; }
else if sha256 != "" then { outputHashAlgo = "sha256"; outputHash = sha256; }
else if sha1 != "" then { outputHashAlgo = "sha1"; outputHash = sha1; }
else throw "fetchurl requires a hash for fixed-output derivation: ${lib.concatStringsSep ", " urls_}";
in in
if md5 != "" then throw "fetchurl does not support md5 anymore, please use sha256 or sha512" stdenvNoCC.mkDerivation {
else if (!hasHash) then throw "Specify hash for fetchurl fixed-output derivation: ${stdenvNoCC.lib.concatStringsSep ", " urls_}"
else stdenvNoCC.mkDerivation {
name = name =
if showURLs then "urls" if showURLs then "urls"
else if name != "" then name else if name != "" then name
@ -121,10 +127,7 @@ else stdenvNoCC.mkDerivation {
preferHashedMirrors = true; preferHashedMirrors = true;
# New-style output content requirements. # New-style output content requirements.
outputHashAlgo = if outputHashAlgo != "" then outputHashAlgo else inherit (hash_) outputHashAlgo outputHash;
if sha512 != "" then "sha512" else if sha256 != "" then "sha256" else "sha1";
outputHash = if outputHash != "" then outputHash else
if sha512 != "" then sha512 else if sha256 != "" then sha256 else sha1;
outputHashMode = if (recursiveHash || executable) then "recursive" else "flat"; outputHashMode = if (recursiveHash || executable) then "recursive" else "flat";

View File

@ -118,6 +118,7 @@ in rec {
initialPath = [ bootstrapTools ]; initialPath = [ bootstrapTools ];
fetchurlBoot = import ../../build-support/fetchurl { fetchurlBoot = import ../../build-support/fetchurl {
inherit lib;
stdenvNoCC = stage0.stdenv; stdenvNoCC = stage0.stdenv;
curl = bootstrapTools; curl = bootstrapTools;
}; };

View File

@ -29,7 +29,8 @@ let inherit (localSystem) system; in
inherit bootstrapTools; inherit bootstrapTools;
fetchurl = import ../../build-support/fetchurl { fetchurl = import ../../build-support/fetchurl {
inherit stdenv; inherit lib;
stdenvNoCC = stdenv;
curl = bootstrapTools; curl = bootstrapTools;
}; };

View File

@ -131,7 +131,7 @@ in
}; };
fetchurl = import ../../build-support/fetchurl { fetchurl = import ../../build-support/fetchurl {
inherit stdenv; inherit lib stdenvNoCC;
# Curl should be in /usr/bin or so. # Curl should be in /usr/bin or so.
curl = null; curl = null;
}; };

View File

@ -195,7 +195,7 @@ with pkgs;
# `fetchurl' downloads a file from the network. # `fetchurl' downloads a file from the network.
fetchurl = import ../build-support/fetchurl { fetchurl = import ../build-support/fetchurl {
inherit stdenvNoCC; inherit lib stdenvNoCC;
# On darwin, libkrb5 needs bootstrap_cmds which would require # On darwin, libkrb5 needs bootstrap_cmds which would require
# converting many packages to fetchurl_boot to avoid evaluation cycles. # converting many packages to fetchurl_boot to avoid evaluation cycles.
curl = buildPackages.curl.override (lib.optionalAttrs stdenv.isDarwin { gssSupport = false; }); curl = buildPackages.curl.override (lib.optionalAttrs stdenv.isDarwin { gssSupport = false; });