@@ -5,47 +5,46 @@
55# (e.g. due to minor changes in the compression algorithm, or changes
66# in timestamps).
77
8−{ fetchurl, unzip }:
8+{ lib, fetchurl, unzip }:
99
10−{ # Optionally move the contents of the unpacked tree up one level.
11− stripRoot ? true
10+{ name ? "source"
1211, url
12+ # Optionally move the contents of the unpacked tree up one level.
13+, stripRoot ? true
1314, extraPostFetch ? ""
14−, name ? "source"
1515, ... } @ args:
1616
1717(fetchurl ({
1818 inherit name;
1919
2020 recursiveHash = true;
21−
2221 downloadToTemp = true;
2322
24− postFetch =
25− ''
26− unpackDir="$TMPDIR/unpack"
27− mkdir "$unpackDir"
28− cd "$unpackDir"
23+ postFetch = ''
24+ unpackDir="$TMPDIR/unpack"
25+ mkdir "$unpackDir"
26+ cd "$unpackDir"
27+
28+ renamed="$TMPDIR/${baseNameOf url}"
29+ mv "$downloadedFile" "$renamed"
30+ unpackFile "$renamed"
31+ result=$unpackDir
32+ ''
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."
38+ exit 1
39+ fi
40+ fn=$(cd "$unpackDir" && echo *)
41+ result="$unpackDir/$fn"
42+ '' + ''
43+ mkdir $out
44+ mv "$result" "$out"
45+ ''
46+ + extraPostFetch;
2947
30− renamed="$TMPDIR/${baseNameOf url}"
31− mv "$downloadedFile" "$renamed"
32− unpackFile "$renamed"
33− ''
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."
38− exit 1
39− fi
40− fn=$(cd "$unpackDir" && echo *)
41− if [ -f "$unpackDir/$fn" ]; then
42− mkdir $out
43− fi
44− mv "$unpackDir/$fn" "$out"
45− '' else ''
46− mv "$unpackDir" "$out"
47− '') #*/
48− + extraPostFetch;
4948} // removeAttrs args [ "stripRoot" "extraPostFetch" ])).overrideAttrs (x: {
5049 # Hackety-hack: we actually need unzip hooks, too
5150 nativeBuildInputs = x.nativeBuildInputs ++ [ unzip ];