From 5b66a505677629e9a72ec89278aca142ce299d4e Mon Sep 17 00:00:00 2001 From: joobisb Date: Thu, 19 Sep 2024 10:14:50 +0530 Subject: [PATCH 1/6] feat: ability to add custom protoc-gen-go dependency to nix flake --- flake.nix | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index bf50122500e88..916c76f8a5f17 100644 --- a/flake.nix +++ b/flake.nix @@ -40,6 +40,28 @@ # From https://nixos.wiki/wiki/Google_Cloud_SDK gdk = pkgs.google-cloud-sdk.withExtraComponents ([ pkgs.google-cloud-sdk.components.gke-gcloud-auth-plugin ]); + customProtocGenGo = 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; + # This should be updated whenever rev changes! + # To update, set to "", run nix-shell, insert new hash + 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 @@ -80,7 +102,7 @@ playwright-driver.browsers postgresql_16 protobuf - protoc-gen-go + customProtocGenGo ripgrep # This doesn't build on latest nixpkgs (July 10 2024) (pinnedPkgs.sapling) From b807081a68b9759004ca91010a81f72e2d1bb93f Mon Sep 17 00:00:00 2001 From: joobisb Date: Thu, 19 Sep 2024 21:55:49 +0530 Subject: [PATCH 2/6] chore: update the naming --- flake.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 916c76f8a5f17..f60dbb7a7db99 100644 --- a/flake.nix +++ b/flake.nix @@ -40,7 +40,7 @@ # From https://nixos.wiki/wiki/Google_Cloud_SDK gdk = pkgs.google-cloud-sdk.withExtraComponents ([ pkgs.google-cloud-sdk.components.gke-gcloud-auth-plugin ]); - customProtocGenGo = pkgs.buildGoModule rec { + proto_gen_go_1_30 = pkgs.buildGoModule rec { name = "protoc-gen-go"; owner = "protocolbuffers"; repo = "protobuf-go"; @@ -102,7 +102,7 @@ playwright-driver.browsers postgresql_16 protobuf - customProtocGenGo + proto_gen_go_1_30 ripgrep # This doesn't build on latest nixpkgs (July 10 2024) (pinnedPkgs.sapling) From 29e30cbcbfcda7fd28f1736740f232d24c49d01f Mon Sep 17 00:00:00 2001 From: joobisb Date: Fri, 20 Sep 2024 17:05:15 +0530 Subject: [PATCH 3/6] updated flake script --- flake.nix | 5 ++--- scripts/update-flake.sh | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index f60dbb7a7db99..4eeb91c25f2de 100644 --- a/flake.nix +++ b/flake.nix @@ -49,8 +49,7 @@ owner = "protocolbuffers"; repo = "protobuf-go"; rev = rev; - # This should be updated whenever rev changes! - # To update, set to "", run nix-shell, insert new hash + # Updated with ./scripts/update-flake.sh`. sha256 = "sha256-GTZQ40uoi62Im2F4YvlZWiSNNJ4fEAkRojYa0EYz9HU="; }; subPackages = [ "cmd/protoc-gen-go" ]; @@ -139,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-biJ4rUJ0lmWqUQLAg0QqyIAaLuZ7e//+loWJIefnrNw="; proxyVendor = true; src = ./.; nativeBuildInputs = with pkgs; [ getopt openssl zstd ]; diff --git a/scripts/update-flake.sh b/scripts/update-flake.sh index 67aca5e79a09a..abc6891e41296 100755 --- a/scripts/update-flake.sh +++ b/scripts/update-flake.sh @@ -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..." @@ -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=$(grep -A 20 'pkgs.buildGoModule rec' flake.nix | grep -A 10 'repo = "protobuf-go"' | grep 'rev = "v' | sed 's/.*rev = "\(.*\)".*/\1/') +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!" From a57d5522bb02545e5daf929280df871e5735e9fc Mon Sep 17 00:00:00 2001 From: joobisb Date: Sat, 21 Sep 2024 00:29:05 +0530 Subject: [PATCH 4/6] refactor flake.nix parser --- flake.nix | 3 ++- scripts/update-flake.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 4eeb91c25f2de..43c0e3e04195c 100644 --- a/flake.nix +++ b/flake.nix @@ -138,7 +138,7 @@ name = "coder-${osArch}"; # Updated with ./scripts/update-flake.sh`. # This should be updated whenever go.mod changes! - vendorHash = "sha256-biJ4rUJ0lmWqUQLAg0QqyIAaLuZ7e//+loWJIefnrNw="; + vendorHash = "sha256-QKgwsJaESo3/7Q5+Fntl2uK6idkn8BT6EAHO8IYlMJQ="; proxyVendor = true; src = ./.; nativeBuildInputs = with pkgs; [ getopt openssl zstd ]; @@ -172,6 +172,7 @@ ''; }; packages = { + proto_gen_go = proto_gen_go_1_30; all = pkgs.buildEnv { name = "all-packages"; paths = devShellPackages; diff --git a/scripts/update-flake.sh b/scripts/update-flake.sh index abc6891e41296..06f5ac13e3d07 100755 --- a/scripts/update-flake.sh +++ b/scripts/update-flake.sh @@ -32,7 +32,7 @@ sed -i "s#\(vendorHash = \"\)[^\"]*#\1${HASH}#" ./flake.nix # Update protoc-gen-go sha256 echo "Updating protoc-gen-go sha256..." -PROTOC_GEN_GO_REV=$(grep -A 20 'pkgs.buildGoModule rec' flake.nix | grep -A 10 'repo = "protobuf-go"' | grep 'rev = "v' | sed 's/.*rev = "\(.*\)".*/\1/') +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 From 333564424fad570ea23fafaf35cef5b556298990 Mon Sep 17 00:00:00 2001 From: Danny Kopping Date: Tue, 24 Sep 2024 14:44:11 +0200 Subject: [PATCH 5/6] make fmt Signed-off-by: Danny Kopping --- scripts/update-flake.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/update-flake.sh b/scripts/update-flake.sh index 06f5ac13e3d07..9287a820b8562 100755 --- a/scripts/update-flake.sh +++ b/scripts/update-flake.sh @@ -6,14 +6,14 @@ 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 + 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 From c86ca8607b4a0be6030419a744ee0c5df3f87a63 Mon Sep 17 00:00:00 2001 From: Danny Kopping Date: Tue, 24 Sep 2024 14:44:49 +0200 Subject: [PATCH 6/6] Update hash Signed-off-by: Danny Kopping --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 43c0e3e04195c..f2d138c2b3aa7 100644 --- a/flake.nix +++ b/flake.nix @@ -138,7 +138,7 @@ name = "coder-${osArch}"; # Updated with ./scripts/update-flake.sh`. # This should be updated whenever go.mod changes! - vendorHash = "sha256-QKgwsJaESo3/7Q5+Fntl2uK6idkn8BT6EAHO8IYlMJQ="; + vendorHash = "sha256-kPXRp7l05iJd4IdvQeOFOgg2UNzBcloy3tA9Meep9VI="; proxyVendor = true; src = ./.; nativeBuildInputs = with pkgs; [ getopt openssl zstd ];