@@ -5,47 +5,46 @@
5# (e.g. due to minor changes in the compression algorithm, or changes
5# (e.g. due to minor changes in the compression algorithm, or changes
6# in timestamps).
6# in timestamps).
8−{ fetchurl, unzip }:
8+{ lib, fetchurl, unzip }:
10−{ # Optionally move the contents of the unpacked tree up one level.
10+{ name ? "source"
12+ # Optionally move the contents of the unpacked tree up one level.
13, extraPostFetch ? ""
14, extraPostFetch ? ""
15, ... } @ args:
15, ... } @ args:
17(fetchurl ({
17(fetchurl ({
18 inherit name;
18 inherit name;
20 recursiveHash = true;
20 recursiveHash = true;
22 downloadToTemp = true;
21 downloadToTemp = true;
24− postFetch =
23+ postFetch = ''
26− unpackDir="$TMPDIR/unpack"
24+ unpackDir="$TMPDIR/unpack"
27− mkdir "$unpackDir"
25+ mkdir "$unpackDir"
28+ renamed="$TMPDIR/${baseNameOf url}"
29+ mv "$downloadedFile" "$renamed"
30+ unpackFile "$renamed"
33+ # Most src disted tarballs have a parent directory like foo-1.2.3/ to strip
34+ + lib.optionalString stripRoot ''
35+ if [ $(ls "$unpackDir" | wc -l) != 1 ]; then
36+ echo "error: zip file must contain a single file or directory."
37+ echo "hint: Pass stripRoot=false; to fetchzip to assume flat list of files."
28− cd "$unpackDir"
40+ fn=$(cd "$unpackDir" && echo *)
41+ result="$unpackDir/$fn"
30− renamed="$TMPDIR/${baseNameOf url}"
31− mv "$downloadedFile" "$renamed"
32− unpackFile "$renamed"
34− + (if stripRoot then ''
35− if [ $(ls "$unpackDir" | wc -l) != 1 ]; then
36− echo "error: zip file must contain a single file or directory."
37− echo "hint: Pass stripRoot=false; to fetchzip to assume flat list of files."
40− fn=$(cd "$unpackDir" && echo *)
41− if [ -f "$unpackDir/$fn" ]; then
44− mv "$unpackDir/$fn" "$out"
46− mv "$unpackDir" "$out"
49} // removeAttrs args [ "stripRoot" "extraPostFetch" ])).overrideAttrs (x: {
48} // removeAttrs args [ "stripRoot" "extraPostFetch" ])).overrideAttrs (x: {
50 # Hackety-hack: we actually need unzip hooks, too
49 # Hackety-hack: we actually need unzip hooks, too
51 nativeBuildInputs = x.nativeBuildInputs ++ [ unzip ];
50 nativeBuildInputs = x.nativeBuildInputs ++ [ unzip ];