From 096198d11f14a1fff2eb335a572c0b20ae52dbf8 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 23 Jul 2008 16:02:58 +0000 Subject: [PATCH] * A quick hack to make nix-prefetch-url support mirror:// URLs. It requires that $NIXPKGS_ALL points at a Nixpkgs tree. --- scripts/nix-prefetch-url.in | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/scripts/nix-prefetch-url.in b/scripts/nix-prefetch-url.in index 2f7b4eeac..1e570a154 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