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 )