1{ lib
2, buildGoModule
3, fetchFromGitHub
4, protobuf
5, git
6, testers
7, buf
8, installShellFiles
9}:
10
11buildGoModule rec {
12 pname = "buf";
13 version = "1.31.0";
14
15 src = fetchFromGitHub {
16 owner = "bufbuild";
17 repo = pname;
18 rev = "v${version}";
19 hash = "sha256-CNt7ZfUMRQNNVusaBgEW64WH1TFYz8yEBfKksGVRVUM=";
20 };
21
22 vendorHash = "sha256-kagSvwxVE+URRY2C5tRtdRwtHBIdQh3BWUG1b3+L8Os=";
23
24 patches = [
25 # Skip a test that requires networking to be available to work,
26 # and a test which requires the source checkout to be part of a git repository
27 ./skip_broken_tests.patch
28 ];
29
30 nativeBuildInputs = [ installShellFiles ];
31
32 ldflags = [ "-s" "-w" ];
33
34 nativeCheckInputs = [
35 git # Required for TestGitCloner
36 protobuf # Required for buftesting.GetProtocFilePaths
37 ];
38
39 preCheck = ''
40 # The tests need access to some of the built utilities
41 export PATH="$PATH:$GOPATH/bin"
42 '';
43
44 # Allow tests that bind or connect to localhost on macOS.
45 __darwinAllowLocalNetworking = true;
46
47 installPhase = ''
48 runHook preInstall
49
50 # Binaries
51 # Only install required binaries, don't install testing binaries
52 for FILE in buf protoc-gen-buf-breaking protoc-gen-buf-lint; do
53 install -D -m 555 -t $out/bin $GOPATH/bin/$FILE
54 done
55
56 # Completions
57 installShellCompletion --cmd buf \
58 --bash <($GOPATH/bin/buf completion bash) \
59 --fish <($GOPATH/bin/buf completion fish) \
60 --zsh <($GOPATH/bin/buf completion zsh)
61
62 # Man Pages
63 mkdir man && $GOPATH/bin/buf manpages man
64 installManPage man/*
65
66 runHook postInstall
67 '';
68
69 passthru.tests.version = testers.testVersion { package = buf; };
70
71 meta = with lib; {
72 homepage = "https://buf.build";
73 changelog = "https://github.com/bufbuild/buf/releases/tag/v${version}";
74 description = "Create consistent Protobuf APIs that preserve compatibility and comply with design best-practices";
75 license = licenses.asl20;
76 maintainers = with maintainers; [ jk lrewega ];
77 };
78}