git.iko.soy/typeable/nixpkgs
on master help sign in
fetchzip, fetchgit: cleanup handling of optional features and whitespace
caff183Benjamin Hipple
pkgs/build-support/fetchgit/default.nix+1−1
@@ -1,4 +1,4 @@
1−{stdenvNoCC, git, cacert}: let
1+{ stdenvNoCC, git, cacert }: let
2 urlToName = url: rev: let
2 urlToName = url: rev: let
3 inherit (stdenvNoCC.lib) removeSuffix splitString last;
3 inherit (stdenvNoCC.lib) removeSuffix splitString last;
4 base = last (splitString ":" (baseNameOf (removeSuffix "/" url)));
4 base = last (splitString ":" (baseNameOf (removeSuffix "/" url)));
pkgs/build-support/fetchgit/nix-prefetch-git+12−13
@@ -1,6 +1,5 @@
1−#! /usr/bin/env bash
1+#!/usr/bin/env bash
2−
3−set -e -o pipefail
2+set -eo pipefail
4
3
5url=
4url=
6rev=
5rev=
@@ -38,17 +37,17 @@ usage(){
38 echo >&2 "syntax: nix-prefetch-git [options] [URL [REVISION [EXPECTED-HASH]]]
37 echo >&2 "syntax: nix-prefetch-git [options] [URL [REVISION [EXPECTED-HASH]]]
39
38
40Options:
39Options:
41− --out path Path where the output would be stored.
40+ --out path Path where the output would be stored.
42− --url url Any url understood by 'git clone'.
41+ --url url Any url understood by 'git clone'.
43− --rev ref Any sha1 or references (such as refs/heads/master)
42+ --rev ref Any sha1 or references (such as refs/heads/master).
44− --hash h Expected hash.
43+ --hash h Expected hash.
45− --branch-name Branch name to check out into
44+ --branch-name Branch name to check out into.
46− --deepClone Clone the entire repository.
45+ --deepClone Clone the entire repository.
47− --no-deepClone Make a shallow clone of just the required ref.
46+ --no-deepClone Make a shallow clone of just the required ref.
48− --leave-dotGit Keep the .git directories.
47+ --leave-dotGit Keep the .git directories.
49 --fetch-submodules Fetch submodules.
48 --fetch-submodules Fetch submodules.
50− --builder Clone as fetchgit does, but url, rev, and out option are mandatory.
49+ --builder Clone as fetchgit does, but url, rev, and out option are mandatory.
51− --quiet Only print the final json summary.
50+ --quiet Only print the final json summary.
52"
51"
53 exit 1
52 exit 1
54}
53}
pkgs/build-support/fetchzip/default.nix+28−29
@@ -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).
7
7
8−{ fetchurl, unzip }:
8+{ lib, fetchurl, unzip }:
9
9
10−{ # Optionally move the contents of the unpacked tree up one level.
10+{ name ? "source"
11− stripRoot ? true
12, url
11, url
12+ # Optionally move the contents of the unpacked tree up one level.
13+, stripRoot ? true
13, extraPostFetch ? ""
14, extraPostFetch ? ""
14−, name ? "source"
15, ... } @ args:
15, ... } @ args:
16
16
17(fetchurl ({
17(fetchurl ({
18 inherit name;
18 inherit name;
19
19
20 recursiveHash = true;
20 recursiveHash = true;
21−
22 downloadToTemp = true;
21 downloadToTemp = true;
23
22
24− postFetch =
23+ postFetch = ''
25− ''
26− unpackDir="$TMPDIR/unpack"
24+ unpackDir="$TMPDIR/unpack"
27− mkdir "$unpackDir"
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
28− cd "$unpackDir"
40+ fn=$(cd "$unpackDir" && echo *)
41+ result="$unpackDir/$fn"
42+ '' + ''
43+ mkdir $out
44+ mv "$result" "$out"
45+ ''
46+ + extraPostFetch;
29
47
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;
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 ];