btrbk: add mainProgram
[NixPkgs.git] / pkgs / by-name / bu / buf / package.nix
blobf77bbf9922f986a5295c2d87e3cf8327b728aafe
1 { lib
2 , buildGoModule
3 , fetchFromGitHub
4 , protobuf_26
5 , git
6 , testers
7 , buf
8 , installShellFiles
9 }:
11 buildGoModule rec {
12   pname = "buf";
13   version = "1.46.0";
15   src = fetchFromGitHub {
16     owner = "bufbuild";
17     repo = "buf";
18     rev = "v${version}";
19     hash = "sha256-XLVEZYQEq9qXrH7EytoHO3QExOAZX6N57amcKBy5ORE=";
20   };
22   vendorHash = "sha256-P1MNwpz3UbaQHLFv5mMs9d0xulitfAD90T1jWxVi5/k=";
24   patches = [
25     # Skip a test that requires networking to be available to work.
26     ./skip_broken_tests.patch
27   ];
29   nativeBuildInputs = [ installShellFiles ];
31   ldflags = [ "-s" "-w" ];
33   nativeCheckInputs = [
34     git # Required for TestGitCloner
35     protobuf_26 # Required for buftesting.GetProtocFilePaths
36   ];
38   checkFlags = [
39     "-skip=TestWorkspaceGit"
40   ];
42   preCheck = ''
43     # For WebAssembly runtime tests
44     GOOS=wasip1 GOARCH=wasm go build -o $GOPATH/bin/buf-plugin-suffix.wasm \
45       ./private/bufpkg/bufcheck/internal/cmd/buf-plugin-suffix
47     # The tests need access to some of the built utilities
48     export PATH="$PATH:$GOPATH/bin"
49   '';
51   # Allow tests that bind or connect to localhost on macOS.
52   __darwinAllowLocalNetworking = true;
54   installPhase = ''
55     runHook preInstall
57     # Binaries
58     # Only install required binaries, don't install testing binaries
59     for FILE in buf protoc-gen-buf-breaking protoc-gen-buf-lint; do
60       install -D -m 555 -t $out/bin $GOPATH/bin/$FILE
61     done
63     # Completions
64     installShellCompletion --cmd buf \
65       --bash <($GOPATH/bin/buf completion bash) \
66       --fish <($GOPATH/bin/buf completion fish) \
67       --zsh <($GOPATH/bin/buf completion zsh)
69     # Man Pages
70     mkdir man && $GOPATH/bin/buf manpages man
71     installManPage man/*
73     runHook postInstall
74   '';
76   passthru.tests.version = testers.testVersion { package = buf; };
78   meta = {
79     homepage = "https://buf.build";
80     changelog = "https://github.com/bufbuild/buf/releases/tag/v${version}";
81     description = "Create consistent Protobuf APIs that preserve compatibility and comply with design best-practices";
82     license = lib.licenses.asl20;
83     maintainers = with lib.maintainers; [ jk lrewega aaronjheng ];
84     mainProgram = "buf";
85   };