about summary refs log tree commit diff
path: root/pkgs/by-name/gi/githooks/package.nix
blob: f4e4cd02bd861465b832fc35989adeb13cf4cb36 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{
  lib,
  buildGoModule,
  fetchFromGitHub,
  git,
  testers,
  makeWrapper,
}:
buildGoModule rec {
  pname = "githooks";
  version = "3.0.2";

  src = fetchFromGitHub {
    owner = "gabyx";
    repo = "githooks";
    rev = "v${version}";
    hash = "sha256-gTvbvW+AFyZUBt7gSKJGc9lrl7CAy+cOElcADlIvuRk=";
  };

  modRoot = "./githooks";
  vendorHash = "sha256-ZcDD4Z/thtyCvXg6GzzKC/FSbh700QEaqXU8FaZaZc4=";

  nativeBuildInputs = [ makeWrapper ];

  buildInputs = [ git ];

  strictDeps = true;

  ldflags = [
    "-s" # Disable symbole table.
    "-w" # Disable DWARF generation.
  ];

  # We need to disable updates and other features:
  # That is done with tag `package_manager_enabled`.
  tags = [ "package_manager_enabled" ];

  checkFlags =
    let
      skippedTests = [
        "TestGithooksCompliesWithGit" # Needs internet to download all hooks documentation.
        "TestUpdateImages" # Needs docker/podman.
      ];
    in
    [
      "-v"
      "-skip"
      "(${builtins.concatStringsSep "|" skippedTests})"
    ];

  doCheck = true;

  # We need to generate some build files before building.
  postConfigure = ''
    GH_BUILD_VERSION="${version}" \
      GH_BUILD_TAG="v${version}" \
      go generate -mod=vendor ./...
  '';

  postInstall = ''
    # Rename executable to proper names.
    mv $out/bin/cli $out/bin/githooks-cli
    mv $out/bin/runner $out/bin/githooks-runner
    mv $out/bin/dialog $out/bin/githooks-dialog
  '';

  postFixup = ''
    wrapProgram "$out/bin/githooks-cli" --prefix PATH : ${lib.makeBinPath [ git ]}
    wrapProgram "$out/bin/githooks-runner" --prefix PATH : ${lib.makeBinPath [ git ]}
  '';

  passthru.tests.version = testers.testVersion {
    package = "githooks-cli";
    command = "githooks-cli --version";
    inherit version;
  };

  meta = with lib; {
    description = "A Git hooks manager with per-repo and shared Git hooks including version control";
    homepage = "https://github.com/gabyx/Githooks";
    license = licenses.mpl20;
    maintainers = with maintainers; [ gabyx ];
    mainProgram = "githooks-cli";
  };
}