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