<nix/fetchurl.nix>: Support downloading and unpacking NARs

This removes the need to have multiple downloads in the stdenv
bootstrap process (like a separate busybox binary for Linux, or
curl/mkdir/sh/bzip2 for Darwin). Now all those files can be combined
into a single NAR.
This commit is contained in:
Eelco Dolstra 2015-10-30 11:27:47 +01:00
parent 5c28943e8f
commit dae5dc7ade
4 changed files with 46 additions and 16 deletions

View file

@ -1,12 +1,19 @@
with import <nix/config.nix>;
{system ? builtins.currentSystem, url, outputHash ? "", outputHashAlgo ? "", md5 ? "", sha1 ? "", sha256 ? "", executable ? false}:
{ system ? builtins.currentSystem
, url
, outputHash ? ""
, outputHashAlgo ? ""
, md5 ? "", sha1 ? "", sha256 ? ""
, executable ? false
, unpack ? false
, name ? baseNameOf (toString url)
}:
assert (outputHash != "" && outputHashAlgo != "")
|| md5 != "" || sha1 != "" || sha256 != "";
derivation {
name = baseNameOf (toString url);
builder = "builtin:fetchurl";
# New-style output content requirements.
@ -14,9 +21,9 @@ derivation {
if sha256 != "" then "sha256" else if sha1 != "" then "sha1" else "md5";
outputHash = if outputHash != "" then outputHash else
if sha256 != "" then sha256 else if sha1 != "" then sha1 else md5;
outputHashMode = if executable then "recursive" else "flat";
outputHashMode = if unpack || executable then "recursive" else "flat";
inherit system url executable;
inherit name system url executable unpack;
# No need to double the amount of network traffic
preferLocalBuild = true;