From a7c209e474c6d63bc959890535747a34da10291d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 23 Jul 2008 16:04:10 +0000 Subject: [PATCH] * Interface to support mirror:// in nix-prefetch-url. The function resolveMirrorURLs produces a file containing the URLs to which a mirror:// URL resolves. svn path=/nixpkgs/trunk/; revision=12410 --- pkgs/build-support/fetchurl/builder.sh | 11 ++++++++++- pkgs/build-support/fetchurl/default.nix | 11 +++++++++-- pkgs/top-level/all-packages.nix | 5 +++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/fetchurl/builder.sh b/pkgs/build-support/fetchurl/builder.sh index 53af63092f4..bfa57143b4b 100644 --- a/pkgs/build-support/fetchurl/builder.sh +++ b/pkgs/build-support/fetchurl/builder.sh @@ -1,6 +1,9 @@ source $stdenv/setup -header "downloading file $name with $outputHashAlgo hash $outputHash..." +if test -n "$showURLs"; then + header "downloading file $name with $outputHashAlgo hash $outputHash..." +fi + # Curl flags to handle redirects, not use EPSV, handle cookies for # servers to need them during redirects, and work on SSL without a @@ -98,6 +101,12 @@ done urls="$urls2" +if test -n "$showURLs"; then + echo "$urls" > $out + exit 0 +fi + + if test -n "$preferHashedMirrors"; then tryHashedMirrors fi diff --git a/pkgs/build-support/fetchurl/default.nix b/pkgs/build-support/fetchurl/default.nix index f502b889047..2643008e33f 100644 --- a/pkgs/build-support/fetchurl/default.nix +++ b/pkgs/build-support/fetchurl/default.nix @@ -20,12 +20,16 @@ , md5 ? "" , sha1 ? "" , sha256 ? "" + +, # If set, don't download the file, but write a list of all possible + # URLs (resulting from resolving mirror:// URLs) to $out. + showURLs ? false }: assert urls != [] -> url == ""; assert url != "" -> urls == []; -assert (outputHash != "" && outputHashAlgo != "") +assert showURLs || (outputHash != "" && outputHashAlgo != "") || md5 != "" || sha1 != "" || sha256 != ""; let @@ -45,7 +49,8 @@ in stdenv.mkDerivation ({ name = - if name != "" then name + if showURLs then "urls" + else if name != "" then name else baseNameOf (toString (builtins.head urls_)); builder = ./builder.sh; buildInputs = [curl]; @@ -76,6 +81,8 @@ stdenv.mkDerivation ({ # command-line. "NIX_HASHED_MIRRORS" ] ++ (map (site: "NIX_MIRRORS_${site}") sites); + + inherit showURLs; } # Pass the mirror locations to the builder. diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 883f323f527..687d10f7edb 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -337,6 +337,11 @@ let pkgs = rec { # linked curl in the case of stdenv-linux). fetchurlBoot = stdenv.fetchurlBoot; + resolveMirrorURLs = {url}: fetchurl { + showURLs = true; + inherit url; + }; + makeInitrd = {contents}: import ../build-support/kernel/make-initrd.nix { inherit stdenv perl cpio contents; };