Skip to content

Commit c127d90

Browse files
authored
chore: add ability to include custom protoc-gen-go dependency in nix flake (#14728)
1 parent 326886d commit c127d90

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

flake.nix

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@
4040
# From https://nixos.wiki/wiki/Google_Cloud_SDK
4141
gdk = pkgs.google-cloud-sdk.withExtraComponents ([ pkgs.google-cloud-sdk.components.gke-gcloud-auth-plugin ]);
4242

43+
proto_gen_go_1_30 = pkgs.buildGoModule rec {
44+
name = "protoc-gen-go";
45+
owner = "protocolbuffers";
46+
repo = "protobuf-go";
47+
rev = "v1.30.0";
48+
src = pkgs.fetchFromGitHub {
49+
owner = "protocolbuffers";
50+
repo = "protobuf-go";
51+
rev = rev;
52+
# Updated with ./scripts/update-flake.sh`.
53+
sha256 = "sha256-GTZQ40uoi62Im2F4YvlZWiSNNJ4fEAkRojYa0EYz9HU=";
54+
};
55+
subPackages = [ "cmd/protoc-gen-go" ];
56+
vendorHash = null;
57+
proxyVendor = true;
58+
preBuild = ''
59+
export GOPROXY=https://proxy.golang.org,direct
60+
go mod download
61+
'';
62+
};
63+
4364
# The minimal set of packages to build Coder.
4465
devShellPackages = with pkgs; [
4566
# google-chrome is not available on OSX and aarch64 linux
@@ -80,7 +101,7 @@
80101
playwright-driver.browsers
81102
postgresql_16
82103
protobuf
83-
protoc-gen-go
104+
proto_gen_go_1_30
84105
ripgrep
85106
# This doesn't build on latest nixpkgs (July 10 2024)
86107
(pinnedPkgs.sapling)
@@ -117,7 +138,7 @@
117138
name = "coder-${osArch}";
118139
# Updated with ./scripts/update-flake.sh`.
119140
# This should be updated whenever go.mod changes!
120-
vendorHash = "sha256-KyMqZxav64rbybUUFoBsOlB6XH7y8aQ7ekaYm0QD4Ew=";
141+
vendorHash = "sha256-kPXRp7l05iJd4IdvQeOFOgg2UNzBcloy3tA9Meep9VI=";
121142
proxyVendor = true;
122143
src = ./.;
123144
nativeBuildInputs = with pkgs; [ getopt openssl zstd ];
@@ -151,6 +172,7 @@
151172
'';
152173
};
153174
packages = {
175+
proto_gen_go = proto_gen_go_1_30;
154176
all = pkgs.buildEnv {
155177
name = "all-packages";
156178
paths = devShellPackages;

scripts/update-flake.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ set -eu
55

66
cd "$(dirname "${BASH_SOURCE[0]}")/.."
77

8+
check_and_install() {
9+
if ! command -v "$1" &>/dev/null; then
10+
echo "$1 is not installed. Attempting to install..."
11+
if ! nix-env -iA nixpkgs."$1"; then
12+
echo "Failed to install $1. Please install it manually and try again."
13+
exit 1
14+
fi
15+
echo "$1 has been installed successfully."
16+
fi
17+
}
18+
19+
check_and_install jq
20+
check_and_install nix-prefetch-git
21+
822
OUT=$(mktemp -d -t nar-hash-XXXXXX)
923

1024
echo "Downloading Go modules..."
@@ -13,4 +27,14 @@ echo "Calculating SRI hash..."
1327
HASH=$(go run tailscale.com/cmd/nardump --sri "$OUT/pkg/mod/cache/download")
1428
sudo rm -rf "$OUT"
1529

30+
echo "Updating go.mod vendorHash"
1631
sed -i "s#\(vendorHash = \"\)[^\"]*#\1${HASH}#" ./flake.nix
32+
33+
# Update protoc-gen-go sha256
34+
echo "Updating protoc-gen-go sha256..."
35+
PROTOC_GEN_GO_REV=$(nix eval --extra-experimental-features nix-command --extra-experimental-features flakes --raw .#proto_gen_go.rev)
36+
echo "protoc-gen-go version: $PROTOC_GEN_GO_REV"
37+
PROTOC_GEN_GO_SHA256=$(nix-prefetch-git https://github.com/protocolbuffers/protobuf-go --rev "$PROTOC_GEN_GO_REV" | jq -r .hash)
38+
sed -i "s#\(sha256 = \"\)[^\"]*#\1${PROTOC_GEN_GO_SHA256}#" ./flake.nix
39+
40+
echo "Flake updated successfully!"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy