Skip to content

chore: add ability to include custom protoc-gen-go dependency in nix flake #14728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@
# From https://nixos.wiki/wiki/Google_Cloud_SDK
gdk = pkgs.google-cloud-sdk.withExtraComponents ([ pkgs.google-cloud-sdk.components.gke-gcloud-auth-plugin ]);

proto_gen_go_1_30 = pkgs.buildGoModule rec {
name = "protoc-gen-go";
owner = "protocolbuffers";
repo = "protobuf-go";
rev = "v1.30.0";
src = pkgs.fetchFromGitHub {
owner = "protocolbuffers";
repo = "protobuf-go";
rev = rev;
# Updated with ./scripts/update-flake.sh`.
sha256 = "sha256-GTZQ40uoi62Im2F4YvlZWiSNNJ4fEAkRojYa0EYz9HU=";
};
subPackages = [ "cmd/protoc-gen-go" ];
vendorHash = null;
proxyVendor = true;
preBuild = ''
export GOPROXY=https://proxy.golang.org,direct
go mod download
'';
};

# The minimal set of packages to build Coder.
devShellPackages = with pkgs; [
# google-chrome is not available on OSX and aarch64 linux
Expand Down Expand Up @@ -80,7 +101,7 @@
playwright-driver.browsers
postgresql_16
protobuf
protoc-gen-go
proto_gen_go_1_30
ripgrep
# This doesn't build on latest nixpkgs (July 10 2024)
(pinnedPkgs.sapling)
Expand Down Expand Up @@ -117,7 +138,7 @@
name = "coder-${osArch}";
# Updated with ./scripts/update-flake.sh`.
# This should be updated whenever go.mod changes!
vendorHash = "sha256-KyMqZxav64rbybUUFoBsOlB6XH7y8aQ7ekaYm0QD4Ew=";
vendorHash = "sha256-kPXRp7l05iJd4IdvQeOFOgg2UNzBcloy3tA9Meep9VI=";
proxyVendor = true;
src = ./.;
nativeBuildInputs = with pkgs; [ getopt openssl zstd ];
Expand Down Expand Up @@ -151,6 +172,7 @@
'';
};
packages = {
proto_gen_go = proto_gen_go_1_30;
all = pkgs.buildEnv {
name = "all-packages";
paths = devShellPackages;
Expand Down
24 changes: 24 additions & 0 deletions scripts/update-flake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ set -eu

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

check_and_install() {
if ! command -v "$1" &>/dev/null; then
echo "$1 is not installed. Attempting to install..."
if ! nix-env -iA nixpkgs."$1"; then
echo "Failed to install $1. Please install it manually and try again."
exit 1
fi
echo "$1 has been installed successfully."
fi
}

check_and_install jq
check_and_install nix-prefetch-git

OUT=$(mktemp -d -t nar-hash-XXXXXX)

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

echo "Updating go.mod vendorHash"
sed -i "s#\(vendorHash = \"\)[^\"]*#\1${HASH}#" ./flake.nix

# Update protoc-gen-go sha256
echo "Updating protoc-gen-go sha256..."
PROTOC_GEN_GO_REV=$(nix eval --extra-experimental-features nix-command --extra-experimental-features flakes --raw .#proto_gen_go.rev)
echo "protoc-gen-go version: $PROTOC_GEN_GO_REV"
PROTOC_GEN_GO_SHA256=$(nix-prefetch-git https://github.com/protocolbuffers/protobuf-go --rev "$PROTOC_GEN_GO_REV" | jq -r .hash)
sed -i "s#\(sha256 = \"\)[^\"]*#\1${PROTOC_GEN_GO_SHA256}#" ./flake.nix

echo "Flake updated successfully!"
Loading