From ea36f3b86892263d172fa3d0d0d4ae00d82a0edc Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 9 May 2014 15:50:40 +0200 Subject: [PATCH] fetchFromGitHub: Use .tar.gz instead of .zip Also clean up the name attribute of fetchzip derivations a bit. --- lib/strings.nix | 10 ++++++++++ pkgs/build-support/fetchurl/default.nix | 5 +---- pkgs/build-support/fetchzip/default.nix | 24 +++++++++++++----------- pkgs/top-level/all-packages.nix | 3 ++- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/lib/strings.nix b/lib/strings.nix index cd748f02cc6..a903aa9fbc4 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -160,6 +160,16 @@ rec { else s; + removeSuffix = suf: s: + let + sufLen = stringLength suf; + sLen = stringLength s; + in + if sufLen <= sLen && suf == substring (sLen - sufLen) sufLen s then + substring 0 (sLen - sufLen) s + else + s; + # Return true iff string v1 denotes a version older than v2. versionOlder = v1: v2: builtins.compareVersions v2 v1 == 1; diff --git a/pkgs/build-support/fetchurl/default.nix b/pkgs/build-support/fetchurl/default.nix index eac38a773c1..f34640901bb 100644 --- a/pkgs/build-support/fetchurl/default.nix +++ b/pkgs/build-support/fetchurl/default.nix @@ -54,9 +54,6 @@ in # first element of `urls'). name ? "" -, # A string to be appended to the name, if the name is derived from `url'. - nameSuffix ? "" - # Different ways of specifying the hash. , outputHash ? "" , outputHashAlgo ? "" @@ -97,7 +94,7 @@ stdenv.mkDerivation { name = if showURLs then "urls" else if name != "" then name - else baseNameOf (toString (builtins.head urls_)) + nameSuffix; + else baseNameOf (toString (builtins.head urls_)); builder = ./builder.sh; diff --git a/pkgs/build-support/fetchzip/default.nix b/pkgs/build-support/fetchzip/default.nix index 6b77b6474ef..7c6e16a0589 100644 --- a/pkgs/build-support/fetchzip/default.nix +++ b/pkgs/build-support/fetchzip/default.nix @@ -1,19 +1,21 @@ -# This function downloads and unpacks a zip file. This is primarily -# useful for dynamically generated zip files, such as GitHub's -# /archive URLs, where the unpacked content of the zip file doesn't -# change, but the zip file itself may (e.g. due to minor changes in -# the compression algorithm, or changes in timestamps). +# This function downloads and unpacks an archive file, such as a zip +# or tar file. This is primarily useful for dynamically generated +# archives, such as GitHub's /archive URLs, where the unpacked content +# of the zip file doesn't change, but the zip file itself may +# (e.g. due to minor changes in the compression algorithm, or changes +# in timestamps). { lib, fetchurl, unzip }: { # Optionally move the contents of the unpacked tree up one level. stripRoot ? true +, url , ... } @ args: -fetchurl (args // { - # Apply a suffix to the name. Otherwise, unpackPhase will get - # confused by the .zip extension. - nameSuffix = "-unpacked"; +fetchurl ({ + # Remove the extension, because otherwise unpackPhase will get + # confused. FIXME: fix unpackPhase. + name = args.name or lib.removeSuffix ".zip" (lib.removeSuffix ".tar.gz" (baseNameOf url)); recursiveHash = true; @@ -24,7 +26,7 @@ fetchurl (args // { export PATH=${unzip}/bin:$PATH mkdir $out cd $out - renamed="$TMPDIR/''${name%-unpacked}" + renamed="$TMPDIR/${baseNameOf url}" mv "$downloadedFile" "$renamed" unpackFile "$renamed" '' @@ -39,4 +41,4 @@ fetchurl (args // { mv $out/$fn/* "$out/" rmdir "$out/$fn" ''; -}) +} // args) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 60389bb7263..5fa278924b6 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -341,7 +341,8 @@ let fetchzip = import ../build-support/fetchzip { inherit lib fetchurl unzip; }; fetchFromGitHub = { owner, repo, rev, sha256 }: fetchzip { - url = "https://github.com/${owner}/${repo}/archive/${rev}.zip"; + name = "${repo}-${rev}-src"; + url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; inherit sha256; };