From 76a8d120a41c2631688f42cc2cab0b225210bc8e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 11 Sep 2007 15:00:49 +0000 Subject: [PATCH] * Allow the user to override the list of mirrors for specific mirror:// sites through environment variables, e.g. NIX_MIRRORS_gnu="ftp://ftp.nluug.nl/pub/gnu/ ftp://ftp.gnu.org/pub/gnu/" or NIX_MIRRORS_sourceforge="http://surfnet.dl.sourceforge.net/sourceforge/" svn path=/nixpkgs/trunk/; revision=9302 --- pkgs/build-support/fetchurl/builder.sh | 10 ++++++++-- pkgs/build-support/fetchurl/default.nix | 19 ++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/pkgs/build-support/fetchurl/builder.sh b/pkgs/build-support/fetchurl/builder.sh index 511839655be0..53af63092f40 100644 --- a/pkgs/build-support/fetchurl/builder.sh +++ b/pkgs/build-support/fetchurl/builder.sh @@ -82,8 +82,14 @@ for url in $urls; do # Assume that SourceForge/GNU/kernel mirrors have better # bandwidth than nix.cs.uu.nl. preferHashedMirrors= - - for url3 in ${!varName}; do + + mirrors=${!varName} + + # Allow command-line override by setting NIX_MIRRORS_$site. + varName="NIX_MIRRORS_$site" + if test -n "${!varName}"; then mirrors="${!varName}"; fi + + for url3 in $mirrors; do urls2="$urls2 $url3$fileName"; done fi diff --git a/pkgs/build-support/fetchurl/default.nix b/pkgs/build-support/fetchurl/default.nix index e752b9313e93..f502b8890472 100644 --- a/pkgs/build-support/fetchurl/default.nix +++ b/pkgs/build-support/fetchurl/default.nix @@ -28,7 +28,20 @@ assert url != "" -> urls == []; assert (outputHash != "" && outputHashAlgo != "") || md5 != "" || sha1 != "" || sha256 != ""; -let urls_ = if urls != [] then urls else [url]; in +let + + urls_ = if urls != [] then urls else [url]; + + mirrors = import ./mirrors.nix; + + # 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 stdenv.mkDerivation ({ name = @@ -62,10 +75,10 @@ stdenv.mkDerivation ({ # This variable allows the user to override hashedMirrors from the # command-line. "NIX_HASHED_MIRRORS" - ]; + ] ++ (map (site: "NIX_MIRRORS_${site}") sites); } # Pass the mirror locations to the builder. -// (import ./mirrors.nix) +// mirrors )