git.iko.soy/typeable/nixpkgs
on master help sign in
fetchzip, fetchgit: cleanup handling of optional features and whitespace

No intended functional difference, just trying to polish to make this easier to extend and more aligned with other nix conventions.

commitcaff18340206c4e5c466c16a534f13505d1098ee authorBenjamin Hipple <bhipple@protonmail.com> dateSun 2 Feb 2020, 16:56 (7 years ago) parent8396961
3 files changed+41−43
pkgs/build-support/fetchgit/default.nix+1−1 pkgs/build-support/fetchgit/nix-prefetch-git+12−13 pkgs/build-support/fetchzip/default.nix+28−29
pkgs/build-support/fetchgit/default.nix+1−1
@@ -1,4 +1,4 @@
1−{stdenvNoCC, git, cacert}: let
1+{ stdenvNoCC, git, cacert }: let
22 urlToName = url: rev: let
33 inherit (stdenvNoCC.lib) removeSuffix splitString last;
44 base = last (splitString ":" (baseNameOf (removeSuffix "/" url)));
pkgs/build-support/fetchgit/nix-prefetch-git+12−13
@@ -1,6 +1,5 @@
1−#! /usr/bin/env bash
2−
3−set -e -o pipefail
1+#!/usr/bin/env bash
2+set -eo pipefail
43
54url=
65rev=
@@ -38,17 +37,17 @@ usage(){
3837 echo >&2 "syntax: nix-prefetch-git [options] [URL [REVISION [EXPECTED-HASH]]]
3938
4039Options:
41− --out path Path where the output would be stored.
42− --url url Any url understood by 'git clone'.
43− --rev ref Any sha1 or references (such as refs/heads/master)
44− --hash h Expected hash.
45− --branch-name Branch name to check out into
46− --deepClone Clone the entire repository.
47− --no-deepClone Make a shallow clone of just the required ref.
48− --leave-dotGit Keep the .git directories.
40+ --out path Path where the output would be stored.
41+ --url url Any url understood by 'git clone'.
42+ --rev ref Any sha1 or references (such as refs/heads/master).
43+ --hash h Expected hash.
44+ --branch-name Branch name to check out into.
45+ --deepClone Clone the entire repository.
46+ --no-deepClone Make a shallow clone of just the required ref.
47+ --leave-dotGit Keep the .git directories.
4948 --fetch-submodules Fetch submodules.
50− --builder Clone as fetchgit does, but url, rev, and out option are mandatory.
51− --quiet Only print the final json summary.
49+ --builder Clone as fetchgit does, but url, rev, and out option are mandatory.
50+ --quiet Only print the final json summary.
5251"
5352 exit 1
5453}
pkgs/build-support/fetchzip/default.nix+28−29
@@ -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 ];