nixpkgs/pkgs/build-support/fetchurl/default.nix
Marc Weber 10f6c2592c adding NIX_CONTINUE_DOWNLOADS feature, see mkdir comment
svn path=/nixpkgs/trunk/; revision=16401
2009-07-16 15:18:26 +00:00

116 lines
3.3 KiB
Nix

# Argh, this thing is duplicated (more-or-less) in Nix (in corepkgs).
# Need to find a way to combine them.
{stdenv, curl, getConfig ? (x: y : "")}: # 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;
} // mirrors);
# Names of the master sites that are mirrored (i.e., "sourceforge",
# "gnu", etc.).
sites =
if builtins ? attrNames
then builtins.attrNames mirrors
else [] /* backwards compatibility */;
in
{ # URL to fetch.
url ? ""
, # Alternatively, a list of URLs specifying alternative download
# locations. They are tried in order.
urls ? []
, # 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 ? ""
, # If set, don't download the file, but write a list of all possible
# URLs (resulting from resolving mirror:// URLs) to $out.
showURLs ? false
}:
assert urls != [] -> url == "";
assert url != "" -> urls == [];
assert showURLs || (outputHash != "" && outputHashAlgo != "")
|| md5 != "" || sha1 != "" || sha256 != "";
let
urls_ = if urls != [] then urls else [url];
in
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://nixos.org/tarballs) over the original URLs.
preferHashedMirrors = true;
# Compatibility with Nix <= 0.7.
id = md5;
# New-style output content requirements.
outputHashAlgo = if outputHashAlgo != "" then outputHashAlgo else
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;
# set this to any value to make nix dowload into /var/nix-downloads/$hash
# so that it can continue a half finished download after a shudown,
# susupend to disk, shutdown etc
# for this to work you have to run
# d=/var/nix-downloads; mkdir $d; chgrp nixbld $d; chmod g+x $d;
# once
# defaulting to enabled because continuing takes place only if $d exists
# and has proper permissions
NIX_CONTINUE_DOWNLOADS = getConfig ["NIX_CONTINUE_DOWNLOADS"] "1";
impureEnvVars = [
# We borrow these environment variables from the caller to allow
# easy proxy configuration. This is impure, but a fixed-output
# derivation like fetchurl is allowed to do so since its result is
# by definition pure.
"http_proxy" "https_proxy" "ftp_proxy" "all_proxy" "no_proxy"
# This variable allows the user to override hashedMirrors from the
# command-line.
"NIX_HASHED_MIRRORS"
] ++ (map (site: "NIX_MIRRORS_${site}") sites);
inherit showURLs mirrorsFile;
}