Add script to automate Nix vendorHash updates (#235)

* Add script to automate Nix vendorHash updates

- Create update-nix-hash.sh to automate vendorHash calculation
- Update vendorHash (to be usedafter recent Go dependency changes)
- Script uses ed for OS agnostic in-place editing and extracts hash from nix output

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix Test Nix Flake CI job

* Revert CI change - bd outputs help by default without 'help' arg

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Steve Yegge <stevey@sourcegraph.com>
This commit is contained in:
Ben Lovell
2025-11-06 19:30:19 +01:00
committed by GitHub
parent c47f40b03e
commit b5e2ef4a59
2 changed files with 25 additions and 1 deletions

View File

@@ -9,7 +9,7 @@ pkgs.buildGoModule {
subPackages = [ "cmd/bd" ]; subPackages = [ "cmd/bd" ];
doCheck = false; doCheck = false;
# Go module dependencies hash (computed via nix build) # Go module dependencies hash (computed via nix build)
vendorHash = "sha256-m/2e3OxM4Ci4KoyH+leEt09C/CpD9SRrwPd39/cZQ9E="; vendorHash = "sha256-eUwVXAe9d/e3OWEav61W8lI0bf/IIQYUol8QUiQiBbo=";
# Git is required for tests # Git is required for tests
nativeBuildInputs = [ pkgs.git ]; nativeBuildInputs = [ pkgs.git ];

24
scripts/update-nix-hash.sh Executable file
View File

@@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -e && cd "$(dirname "$0")/.."
# Update the vendorHash in default.nix after Go dependency changes
# Usage: ./scripts/update-nix-hash.sh
echo "Getting correct vendorHash from nix..."
# Set pkgs.lib.fakeHash to force nix to output the correct one
printf ',s|vendorHash = ".*";|vendorHash = pkgs.lib.fakeHash;|\nw\n' | ed -s default.nix
# Extract correct hash from nix build error
CORRECT_HASH=$(nix build --no-link 2>&1 | grep "got:" | awk '{print $2}')
if [ -z "$CORRECT_HASH" ]; then
echo "Error: Could not get hash from nix build"
git restore default.nix
exit 1
fi
# Update with correct hash
printf ',s|vendorHash = pkgs\.lib\.fakeHash;|vendorHash = "%s";|\nw\n' "$CORRECT_HASH" | ed -s default.nix
echo "✓ Updated vendorHash to: $CORRECT_HASH"