nixpkgs/pkgs/build-support/fetchurl/default.nix

128 lines
3.8 KiB
Nix
Raw Normal View History

{ stdenv, curl }: # Note that `curl' may be `null', in case of the native stdenv.
let
mirrors = import ./mirrors.nix;
# Write the list of mirrors to a file that we can reuse between
# fetchurl instantiations, instead of passing the mirrors to
# fetchurl instantiations via environment variables. This makes the
# resulting store derivations (.drv files) much smaller, which in
# turn makes nix-env/nix-instantiate faster.
mirrorsFile =
stdenv.mkDerivation ({
name = "mirrors-list";
builder = ./write-mirror-list.sh;
preferLocalBuild = true;
} // mirrors);
# Names of the master sites that are mirrored (i.e., "sourceforge",
# "gnu", etc.).
sites = builtins.attrNames mirrors;
impureEnvVars = stdenv.lib.fetchers.proxyImpureEnvVars ++ [
# This variable allows the user to pass additional options to curl
"NIX_CURL_FLAGS"
# This variable allows the user to override hashedMirrors from the
# command-line.
"NIX_HASHED_MIRRORS"
# This variable allows overriding the timeout for connecting to
# the hashed mirrors.
"NIX_CONNECT_TIMEOUT"
] ++ (map (site: "NIX_MIRRORS_${site}") sites);
in
{ # URL to fetch.
url ? ""
, # Alternatively, a list of URLs specifying alternative download
# locations. They are tried in order.
urls ? []
, # Additional curl options needed for the download to succeed.
curlOpts ? ""
, # Name of the file. If empty, use the basename of `url' (or of the
# first element of `urls').
name ? ""
# Different ways of specifying the hash.
, outputHash ? ""
, outputHashAlgo ? ""
, md5 ? ""
, sha1 ? ""
, sha256 ? ""
2016-04-13 10:56:51 +00:00
, sha512 ? ""
, recursiveHash ? false
, # Shell code executed after the file has been fetched
# successfully. This can do things like check or transform the file.
postFetch ? ""
, # Whether to download to a temporary path rather than $out. Useful
# in conjunction with postFetch. The location of the temporary file
# is communicated to postFetch via $downloadedFile.
downloadToTemp ? false
2016-01-19 10:17:49 +00:00
, # If true, set executable bit on downloaded file
executable ? false
, # If set, don't download the file, but write a list of all possible
# URLs (resulting from resolving mirror:// URLs) to $out.
showURLs ? false
, # Meta information, if any.
meta ? {}
}:
assert builtins.isList urls;
assert (urls == []) != (url == "");
assert sha512 != "" -> builtins.compareVersions "1.11" builtins.nixVersion <= 0;
* The stdenv setup script now defines a generic builder that allows builders for typical Autoconf-style to be much shorten, e.g., . $stdenv/setup genericBuild The generic builder does lots of stuff automatically: - Unpacks source archives specified by $src or $srcs (it knows about gzip, bzip2, tar, zip, and unpacked source trees). - Determines the source tree. - Applies patches specified by $patches. - Fixes libtool not to search for libraries in /lib etc. - Runs `configure'. - Runs `make'. - Runs `make install'. - Strips debug information from static libraries. - Writes nested log information (in the format accepted by `log2xml'). There are also lots of hooks and variables to customise the generic builder. See `stdenv/generic/docs.txt'. * Adapted the base packages (i.e., the ones used by stdenv) to use the generic builder. * We now use `curl' instead of `wget' to download files in `fetchurl'. * Neither `curl' nor `wget' are part of stdenv. We shouldn't encourage people to download stuff in builders (impure!). * Updated some packages. * `buildinputs' is now `buildInputs' (but the old name also works). * `findInputs' in the setup script now prevents inputs from being processed multiple times (which could happen, e.g., if an input was a propagated input of several other inputs; this caused the size variables like $PATH to blow up exponentially in the worst case). * Patched GNU Make to write nested log information in the format accepted by `log2xml'. Also, prior to writing the build command, Make now writes a line `building X' to indicate what is being built. This is unfortunately often obscured by the gigantic tool invocations in many Makefiles. The actual build commands are marked `unimportant' so that they don't clutter pages generated by `log2html'. svn path=/nixpkgs/trunk/; revision=845
2004-03-19 16:53:04 +00:00
let
hasHash = showURLs || (outputHash != "" && outputHashAlgo != "")
2016-04-13 10:56:51 +00:00
|| md5 != "" || sha1 != "" || sha256 != "" || sha512 != "";
urls_ = if urls != [] then urls else [url];
in
if (!hasHash) then throw "Specify hash for fetchurl fixed-output derivation: ${stdenv.lib.concatStringsSep ", " urls_}" else stdenv.mkDerivation {
name =
if showURLs then "urls"
else if name != "" then name
else baseNameOf (toString (builtins.head urls_));
builder = ./builder.sh;
buildInputs = [ curl ];
urls = urls_;
# If set, prefer the content-addressable mirrors
# (http://tarballs.nixos.org) over the original URLs.
preferHashedMirrors = true;
# New-style output content requirements.
outputHashAlgo = if outputHashAlgo != "" then outputHashAlgo else
2016-04-13 10:56:51 +00:00
if sha512 != "" then "sha512" else if sha256 != "" then "sha256" else if sha1 != "" then "sha1" else "md5";
outputHash = if outputHash != "" then outputHash else
if sha512 != "" then sha512 else if sha256 != "" then sha256 else if sha1 != "" then sha1 else
(stdenv.lib.fetchMD5warn "fetchurl" (builtins.head urls_) md5);
2016-01-19 10:17:49 +00:00
outputHashMode = if (recursiveHash || executable) then "recursive" else "flat";
2016-01-19 10:17:49 +00:00
inherit curlOpts showURLs mirrorsFile impureEnvVars postFetch downloadToTemp executable;
# Doing the download on a remote machine just duplicates network
# traffic, so don't do that.
preferLocalBuild = true;
inherit meta;
}