base16-schemes: unstable-2024-06-21 -> unstable-2024-11-12
[NixPkgs.git] / pkgs / by-name / ve / vexctl / package.nix
blobcc1d18ab74d68c8516331472e4feaeb4cc87bbf5
1 { lib
2 , buildGoModule
3 , fetchFromGitHub
4 , installShellFiles
5 }:
7 buildGoModule rec {
8   pname = "vexctl";
9   version = "0.1.0";
11   src = fetchFromGitHub {
12     owner = "chainguard-dev";
13     repo = "vex";
14     rev = "v${version}";
15     hash = "sha256-f5UVX6x4DwjlcgMAv0GuKBH9UUzFhQ8pW8l+9pc7RQ4=";
16     # populate values that require us to use git. By doing this in postFetch we
17     # can delete .git afterwards and maintain better reproducibility of the src.
18     leaveDotGit = true;
19     postFetch = ''
20       cd "$out"
21       git rev-parse HEAD > $out/COMMIT
22       # '0000-00-00T00:00:00Z'
23       date -u -d "@$(git log -1 --pretty=%ct)" "+'%Y-%m-%dT%H:%M:%SZ'" > $out/SOURCE_DATE_EPOCH
24       find "$out" -name .git -print0 | xargs -0 rm -rf
25     '';
26   };
27   vendorHash = "sha256-GZIssLLPg2dF7xsvsYn2MKYunMCpGbNA+6qCYBW++vk=";
29   nativeBuildInputs = [ installShellFiles ];
31   ldflags = [
32     "-s"
33     "-w"
34     "-X sigs.k8s.io/release-utils/version.gitVersion=v${version}"
35     "-X sigs.k8s.io/release-utils/version.gitTreeState=clean"
36   ];
38   # ldflags based on metadata from git and source
39   preBuild = ''
40     ldflags+=" -X sigs.k8s.io/release-utils/version.gitCommit=$(cat COMMIT)"
41     ldflags+=" -X sigs.k8s.io/release-utils/version.buildDate=$(cat SOURCE_DATE_EPOCH)"
42   '';
44   postBuild = ''
45     mv $GOPATH/bin/vex{,ctl}
46   '';
48   postInstall = ''
49     installShellCompletion --cmd vexctl \
50       --bash <($out/bin/vexctl completion bash) \
51       --fish <($out/bin/vexctl completion fish) \
52       --zsh <($out/bin/vexctl completion zsh)
53   '';
55   doInstallCheck = true;
56   installCheckPhase = ''
57     runHook preInstallCheck
58     $out/bin/vexctl --help
59     $out/bin/vexctl version 2>&1 | grep "v${version}"
60     runHook postInstallCheck
61   '';
63   meta = with lib; {
64     homepage = "https://github.com/chainguard-dev/vex/";
65     description = "Tool to attest VEX impact statements";
66     mainProgram = "vexctl";
67     license = licenses.asl20;
68     maintainers = with maintainers; [ jk ];
69   };