Skip to content

Commit

Permalink
feat: update nix hashes on version update
Browse files Browse the repository at this point in the history
  • Loading branch information
jadepark-dev committed Sep 5, 2024
1 parent 8feb8cf commit d2b8a2a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
51 changes: 51 additions & 0 deletions scripts/update-solana-nix-hashes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

# Solana Nix Package SHA256 Hash Updater
#
# This script updates the SHA256 hashes for Solana binaries in the solana.nix file.
#
# Usage: ./update_nix_hashes.sh <version>

set -e

if [ $# -eq 0 ]; then
echo "Error: No version provided"
echo "Usage: $0 <version>"
exit 1
fi

VERSION=$1

echo "Updating SHA256 hashes for Nix packages (Solana version: $VERSION)"

get_nix_hash() {
local url=$1
nix hash convert --hash-algo sha256 $(nix-prefetch-url --unpack $url)
}

linux_hash=$(get_nix_hash https://github.com/anza-xyz/agave/releases/download/${VERSION}/solana-release-x86_64-unknown-linux-gnu.tar.bz2)
darwin_hash=$(get_nix_hash https://github.com/anza-xyz/agave/releases/download/${VERSION}/solana-release-aarch64-apple-darwin.tar.bz2)

echo "Linux Hash: $linux_hash"
echo "Darwin Hash: $darwin_hash"

LINUX_START_MARKER="### BEGIN_LINUX_SHA256 ###"
LINUX_END_MARKER="### END_LINUX_SHA256 ###"
DARWIN_START_MARKER="### BEGIN_DARWIN_SHA256 ###"
DARWIN_END_MARKER="### END_DARWIN_SHA256 ###"

if [ "$(uname -s)" = "Darwin" ]; then
sed_in_place=(-i '')
else
sed_in_place=(-i)
fi

sed "${sed_in_place[@]}" \
-e "/$LINUX_START_MARKER/,/$LINUX_END_MARKER/ s|sha256 = \"[^\"]*\"|sha256 = \"$linux_hash\"|" \
solana.nix

sed "${sed_in_place[@]}" \
-e "/$DARWIN_START_MARKER/,/$DARWIN_END_MARKER/ s|sha256 = \"[^\"]*\"|sha256 = \"$darwin_hash\"|" \
solana.nix

echo "Updated hashes in solana.nix"
4 changes: 3 additions & 1 deletion scripts/update-solana.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ else
sed -i -e "s~$containerVersion~$latestContainer~" scripts/setup-localnet/localnet.sh
sed -i -e "s~$nixVersion~$latestNix~" solana.nix
fi
cd ..

# Update the Nix hashes
"$(dirname -- "$0")/update-solana-nix-hashes.sh" "$latestTag"

echo "Done"
12 changes: 10 additions & 2 deletions solana.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,24 @@ let

# It provides two derivations, one for x86_64-linux and another for aarch64-apple-darwin.
# Each derivation downloads the corresponding Solana release.

# The SHA256 hashes below are automatically updated by action.(dependency-updates.yml)
# The update script(./scripts/update-solana-nix-hashes.sh) looks for the BEGIN and END markers to locate the lines to modify.
# Do not modify these markers or the lines between them manually.
solanaBinaries = {
x86_64-linux = getBinDerivation {
name = "solana-cli-x86_64-linux";
filename = "solana-release-x86_64-unknown-linux-gnu.tar.bz2";
sha256 = "sha256-bgT7Xqnz6V8tsv5WSESbSUfJCPfGWjGHGYvpEG0myxk=";
### BEGIN_LINUX_SHA256 ###
sha256 = "sha256-L7N8z1MjDWkSoOKLAe4y/iuKTRgLpqg2mDpb9h1RXH0=";
### END_LINUX_SHA256 ###
};
aarch64-apple-darwin = getBinDerivation {
name = "solana-cli-aarch64-apple-darwin";
filename = "solana-release-aarch64-apple-darwin.tar.bz2";
sha256 = "sha256-eqJcoheUCACcIfNNgMGhbhYnAyAy9PGarlWhzr4JpbU=";
### BEGIN_DARWIN_SHA256 ###
sha256 = "sha256-D6hJL3yQncHltuWtF4QMAzvp/s7LV/S3NHwHiJG8wQ0=";
### END_DARWIN_SHA256 ###
};
};
in
Expand Down

0 comments on commit d2b8a2a

Please sign in to comment.