Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
updated flake script
  • Loading branch information
joobisb committed Sep 20, 2024
commit 29e30cbcbfcda7fd28f1736740f232d24c49d01f
5 changes: 2 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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" ];
Expand Down Expand Up @@ -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 ];
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=$(grep -A 20 'pkgs.buildGoModule rec' flake.nix | grep -A 10 'repo = "protobuf-go"' | grep 'rev = "v' | sed 's/.*rev = "\(.*\)".*/\1/')
Copy link
Contributor

@dannykopping dannykopping Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is flimsy (and possibly not portable across Linux/Mac/Windows); is there a more robust way we can get this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dannykopping
found a way to do this using nix eval , please have a look

Refer: https://discourse.nixos.org/t/how-to-evaluate-a-nix-value-from-a-shell-script/24296/3

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