summary refs log tree commit diff
path: root/pkgs/by-name/gi/git-get/package.nix
blob: 8cd852c5d757b949152485512c34ac0d0529bfeb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{ lib, fetchFromGitHub, git, buildGoModule }:

let config-module = "git-get/pkg/cfg";
in
buildGoModule rec {
  pname = "git-get";
  version = "0.5.0";

  src = fetchFromGitHub {
    owner = "grdl";
    repo = pname;
    rev = "v${version}";
    hash = "sha256-v98Ff7io7j1LLzciHNWJBU3LcdSr+lhwYrvON7QjyCI=";
    # populate values that require us to use git. By doing this in postFetch we
    # can delete .git afterwards and maintain better reproducibility of the src.
    leaveDotGit = true;
    postFetch = ''
      git -C $out rev-parse HEAD > $out/COMMIT
      # in format of 0000-00-00T00:00:00Z
      date -u -d "@$(git -C $out log -1 --pretty=%ct)" "+%Y-%m-%dT%H:%M:%SZ" > $out/SOURCE_DATE_EPOCH
      find "$out" -name .git -print0 | xargs -0 rm -rf
    '';
  };

  vendorHash = "sha256-C+XOjMDMFneKJNeBh0KWPx8yM7XiiIpTlc2daSfhZhY=";

  doCheck = false;

  # ldflags based on metadata from git and source
  preBuild = ''
    ldflags+=" -X ${config-module}.commit=$(cat COMMIT)"
    ldflags+=" -X ${config-module}.date=$(cat SOURCE_DATE_EPOCH)"
  '';

  ldflags = [
    "-s"
    "-w"
    "-X ${config-module}.version=v${version}"
  ];

  preInstall = ''
    mv "$GOPATH/bin/get" "$GOPATH/bin/git-get"
    mv "$GOPATH/bin/list" "$GOPATH/bin/git-list"
  '';

  meta = with lib; {
    description = "A better way to clone, organize and manage multiple git repositories";
    homepage = "https://github.com/grdl/git-get";
    license = licenses.mit;
    maintainers = with maintainers; [ sumnerevans ];
  };
}