about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2007-08-27 12:44:01 +0000
committerEelco Dolstra <eelco.dolstra@logicblox.com>2007-08-27 12:44:01 +0000
commit45a2c87402c70f14cd6b4505e7b9c6f1872fb546 (patch)
tree6504fc4bd01d91f50182a3a37be6e85ecd78e83c /pkgs/build-support
parent6d4fa01f1e681be36f3122b2359b953a8e41ccc7 (diff)
downloadnixlib-45a2c87402c70f14cd6b4505e7b9c6f1872fb546.tar
nixlib-45a2c87402c70f14cd6b4505e7b9c6f1872fb546.tar.gz
nixlib-45a2c87402c70f14cd6b4505e7b9c6f1872fb546.tar.bz2
nixlib-45a2c87402c70f14cd6b4505e7b9c6f1872fb546.tar.lz
nixlib-45a2c87402c70f14cd6b4505e7b9c6f1872fb546.tar.xz
nixlib-45a2c87402c70f14cd6b4505e7b9c6f1872fb546.tar.zst
nixlib-45a2c87402c70f14cd6b4505e7b9c6f1872fb546.zip
* Support for mirror:// URLs a la Gentoo (NIXPKGS-70). Instead of
    fetchurl {
      url = http://heanet.dl.sourceforge.net/sourceforge/zapping/zapping-0.9.6.tar.bz2;
      md5 = "8306775c6a11de4d72345b5eee970ea6";
    };

  you can write

    fetchurl {
      url = mirror://sourceforge/zapping/zapping-0.9.6.tar.bz2;
      md5 = "8306775c6a11de4d72345b5eee970ea6";
    };

  which causes fetchurl to try the SourceForge mirrors listed in the
  `sourceforge' attribute in build-support/fetchurl/mirrors.nix.
  (They're currently tried in sequence, and the lists of mirrors are
  not configurable yet.)

  The syntax for mirror URLs is mirror://site/path/to/file, where
  `site' is currently one of `sourceforge', `gnu' (mirrors of
  ftp://ftp.gnu.org/pub/gnu) and `kernel' (mirrors of
  http://www.all.kernel.org/pub/).

svn path=/nixpkgs/trunk/; revision=9197
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/fetchurl/builder.sh56
-rw-r--r--pkgs/build-support/fetchurl/default.nix14
-rw-r--r--pkgs/build-support/fetchurl/mirrors.nix35
3 files changed, 89 insertions, 16 deletions
diff --git a/pkgs/build-support/fetchurl/builder.sh b/pkgs/build-support/fetchurl/builder.sh
index c6ccf708855f..f91edf7c2818 100644
--- a/pkgs/build-support/fetchurl/builder.sh
+++ b/pkgs/build-support/fetchurl/builder.sh
@@ -45,22 +45,52 @@ finish() {
 }
 
 
-for mirror in $hashedMirrors; do
-    url="$mirror/$outputHashAlgo/$outputHash"
-    if $curl --fail --silent --show-error --head "$url" \
-        --write-out "%{http_code}" --output /dev/null > code 2> log; then
-        tryDownload "$url"
-        if test -n "$success"; then finish; fi
+tryHashedMirrors() {
+    for mirror in $hashedMirrors; do
+        url="$mirror/$outputHashAlgo/$outputHash"
+        if $curl --fail --silent --show-error --head "$url" \
+            --write-out "%{http_code}" --output /dev/null > code 2> log; then
+            tryDownload "$url"
+            if test -n "$success"; then finish; fi
+        else
+            # Be quiet about 404 errors, which we interpret as the file
+            # not being present on this particular mirror.
+            if test "$(cat code)" != 404; then
+                echo "error checking the existence of $url:"
+                cat log
+            fi
+        fi
+    done
+}
+
+
+urls2=
+for url in $urls; do
+    if test "${url:0:9}" != "mirror://"; then
+        urls2="$urls2 $url"
     else
-        # Be quiet about 404 errors, which we interpret as the file
-        # not being present on this particular mirror.
-        if test "$(cat code)" != 404; then
-            echo "error checking the existence of $url:"
-            cat log
+        url2="${url:9}"; echo "${url2/\// }" > split; read site fileName < split
+        #varName="mirror_$site"
+        varName="$site" # !!! danger of name clash, fix this
+        if test -z "${!varName}"; then
+            echo "warning: unknown mirror:// site \`$site'"
+        else
+            # Assume that SourceForge/GNU/kernel mirrors have better
+            # bandwidth than nix.cs.uu.nl.
+            preferHashedMirrors=
+            
+            for url3 in ${!varName}; do
+                urls2="$urls2 $url3$fileName";
+            done
         fi
     fi
 done
+urls="$urls2"
+
 
+if test -n "$preferHashedMirrors"; then
+    tryHashedMirrors
+fi
 
 success=
 for url in $urls; do
@@ -68,6 +98,10 @@ for url in $urls; do
     if test -n "$success"; then finish; fi
 done
 
+if test -z "$preferHashedMirrors"; then
+    tryHashedMirrors
+fi
+
 
 echo "error: cannot download $name from any mirror"
 exit 1
diff --git a/pkgs/build-support/fetchurl/default.nix b/pkgs/build-support/fetchurl/default.nix
index c79f3d214c64..eb40c4c6a910 100644
--- a/pkgs/build-support/fetchurl/default.nix
+++ b/pkgs/build-support/fetchurl/default.nix
@@ -30,7 +30,7 @@ assert (outputHash != "" && outputHashAlgo != "")
 
 let urls_ = if urls != [] then urls else [url]; in
 
-stdenv.mkDerivation {
+stdenv.mkDerivation ({
   name =
     if name != "" then name
     else baseNameOf (toString (builtins.head urls_));
@@ -39,10 +39,9 @@ stdenv.mkDerivation {
 
   urls = urls_;
 
-  # The content-addressable mirrors.
-  hashedMirrors = [
-    http://nix.cs.uu.nl/dist/tarballs
-  ];
+  # If set, prefer the content-addressable mirrors
+  # (http://nix.cs.uu.nl/dist/tarballs) over the original URLs.
+  preferHashedMirrors = true;
 
   # Compatibility with Nix <= 0.7.
   id = md5;
@@ -59,3 +58,8 @@ stdenv.mkDerivation {
   # by definition pure.
   impureEnvVars = ["http_proxy" "https_proxy" "ftp_proxy" "all_proxy" "no_proxy"];
 }
+
+# Pass the mirror locations to the builder.
+// (import ./mirrors.nix)
+
+)
diff --git a/pkgs/build-support/fetchurl/mirrors.nix b/pkgs/build-support/fetchurl/mirrors.nix
new file mode 100644
index 000000000000..3ffbf706eb2d
--- /dev/null
+++ b/pkgs/build-support/fetchurl/mirrors.nix
@@ -0,0 +1,35 @@
+{
+  # Content-addressable Nix mirrors.
+  hashedMirrors = [
+    http://nix.cs.uu.nl/dist/tarballs
+  ];
+
+  # Mirrors for mirror://site/filename URIs, where "site" is
+  # "sourceforge", "gnu", etc.
+  
+  # SourceForge.
+  sourceforge = [
+    http://prdownloads.sourceforge.net/
+    http://heanet.dl.sourceforge.net/sourceforge/
+    http://surfnet.dl.sourceforge.net/sourceforge/
+    http://dfn.dl.sourceforge.net/sourceforge/
+    http://mesh.dl.sourceforge.net/sourceforge/
+    http://ovh.dl.sourceforge.net/sourceforge/
+    http://osdn.dl.sourceforge.net/sourceforge/
+    http://kent.dl.sourceforge.net/sourceforge/
+  ];
+
+  # GNU.
+  gnu = [
+    ftp://ftp.nluug.nl/pub/gnu/
+    http://mirrors.kernel.org/gnu/
+    http://ftp.gnu.org/pub/gnu/
+  ];
+
+  # kernel.org's /pub (/pub/{linux,software}) tree.
+  kernel = [
+    http://www.all.kernel.org/pub/
+    http://www.eu.kernel.org/pub/
+    http://www.de.kernel.org/pub/
+  ];
+}