about summary refs log tree commit diff
path: root/scripts/nix-prefetch-url.in
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2008-07-23T16·02+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2008-07-23T16·02+0000
commit096198d11f14a1fff2eb335a572c0b20ae52dbf8 (patch)
treee4f02359a08f95317f7d5293a316ee1727bbe931 /scripts/nix-prefetch-url.in
parent660244f65f5d3cb445c874b25fcf6494b3c1df3a (diff)
* A quick hack to make nix-prefetch-url support mirror:// URLs. It
  requires that $NIXPKGS_ALL points at a Nixpkgs tree.

Diffstat (limited to 'scripts/nix-prefetch-url.in')
-rw-r--r--scripts/nix-prefetch-url.in22
1 files changed, 22 insertions, 0 deletions
diff --git a/scripts/nix-prefetch-url.in b/scripts/nix-prefetch-url.in
index 2f7b4eeac848..1e570a1544da 100644
--- a/scripts/nix-prefetch-url.in
+++ b/scripts/nix-prefetch-url.in
@@ -37,6 +37,7 @@ fi
 
 
 mkTempDir() {
+    if test -n "$tmpPath"; then return; fi
     local i=0
     while true; do
         if test -z "$TMPDIR"; then TMPDIR=/tmp; fi
@@ -64,6 +65,27 @@ doDownload() {
 }
 
 
+# Hack to support the mirror:// scheme from Nixpkgs.
+if test "${url:0:9}" = "mirror://"; then
+    if test -z "$NIXPKGS_ALL"; then
+        echo "Resolving mirror:// URLs requires Nixpkgs.  Please point \$NIXPKGS_ALL at a Nixpkgs tree." >&2
+        exit 1
+    fi
+
+    mkTempDir
+    nix-build "$NIXPKGS_ALL" -A resolveMirrorURLs --argstr url "$url" -o $tmpPath/urls > /dev/null
+
+    expanded=($(cat $tmpPath/urls))
+    if test "${#expanded[*]}" = 0; then
+        echo "$0: cannot resolve $url." >&2
+        exit 1
+    fi
+
+    echo "$url expands to ${expanded[*]} (using ${expanded[0]})" >&2
+    url="${expanded[0]}"
+fi
+
+
 # If we don't know the hash or a file with that hash doesn't exist,
 # download the file and add it to the store.
 if test -z "$finalPath"; then