nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
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.4.0";
14
15 src = fetchFromGitHub {
16 owner = "bufbuild";
17 repo = pname;
18 rev = "v${version}";
19 sha256 = "sha256-cKb9pZYEsO1thgtl/8XFJHpNrO6P3OR8Lox/Gf9ccYk=";
20 };
21
22 vendorSha256 = "sha256-zXLvKEdiIFnmwWQBgbJHCEBe2i7FobgeUOnA3LvHl8w=";
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 checkInputs = [
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 installPhase = ''
48 runHook preInstall
49
50 # Binaries
51 mkdir -p "$out/bin"
52 # Only install required binaries, don't install testing binaries
53 for FILE in \
54 "buf" \
55 "protoc-gen-buf-breaking" \
56 "protoc-gen-buf-lint"; do
57 cp "$GOPATH/bin/$FILE" "$out/bin/"
58 done
59
60 # Completions
61 installShellCompletion --cmd buf \
62 --bash <($GOPATH/bin/buf completion bash) \
63 --fish <($GOPATH/bin/buf completion fish) \
64 --zsh <($GOPATH/bin/buf completion zsh)
65
66 # Man Pages
67 mkdir man && $GOPATH/bin/buf manpages man
68 installManPage man/*
69
70 runHook postInstall
71 '';
72
73 passthru.tests.version = testers.testVersion { package = buf; };
74
75 meta = with lib; {
76 homepage = "https://buf.build";
77 changelog = "https://github.com/bufbuild/buf/releases/tag/v${version}";
78 description = "Create consistent Protobuf APIs that preserve compatibility and comply with design best-practices";
79 license = licenses.asl20;
80 maintainers = with maintainers; [ raboof jk lrewega ];
81 };
82}