Create update.sh script that fetches the latest claude-code version and SHA256 hashes from Homebrew cask and automatically updates the Nix package definition. Features: - Fetches version and all 4 platform SHA256 hashes from Homebrew - Updates default.nix in-place using awk for reliable parsing - Validates extracted data before updating - Supports --dry-run mode to preview changes - Supports --help flag for usage information - Idempotent (safe to run multiple times) Update README to document the automated update method as the recommended approach, with manual update as a fallback option.
2.9 KiB
claude-cli
Custom Nix package for Claude Code CLI.
Why This Package Exists
The official claude-code package in nixpkgs tries to fetch from npm registry, which is blocked by Block's corporate security (Cloudflare Teams dependency confusion protection). This custom package fetches directly from Anthropic's Google Cloud Storage distribution, bypassing the npm registry entirely.
Updating to a New Version
Automated Update (Recommended)
Run the update script to automatically fetch and update to the latest version:
cd packages/claude-cli
./update.sh
The script will:
- Fetch the latest version from Homebrew cask
- Update version and all SHA256 hashes in default.nix
- Show you what changed
For a dry-run to see what would change:
./update.sh --dry-run
After the script completes, follow the "Test the Build" steps below.
Manual Update
If you prefer to update manually, or if the automated script fails:
1. Find the Latest Version and Hashes
Check the Homebrew cask formula for the latest version info:
curl -s "https://raw.githubusercontent.com/Homebrew/homebrew-cask/HEAD/Casks/c/claude-code.rb" | head -50
This will show:
- The latest
versionnumber - SHA256 hashes for all platforms (
arm64,x86_64,x86_64_linux,arm64_linux)
2. Update default.nix
Edit default.nix and update:
-
The
versionvariable (line 9):version = "2.0.51"; # Update this -
All four platform sha256 hashes in the
srcsattribute set (lines 11-27):aarch64-darwin = { sha256 = "..."; # Update from Homebrew cask "arm:" value }; x86_64-darwin = { sha256 = "..."; # Update from Homebrew cask "x86_64:" value }; x86_64-linux = { sha256 = "..."; # Update from Homebrew cask "x86_64_linux:" value }; aarch64-linux = { sha256 = "..."; # Update from Homebrew cask "arm64_linux:" value };
3. Test the Build
Before committing, test that the package builds successfully:
NIXPKGS_ALLOW_UNFREE=1 nix-build -E 'with import <nixpkgs> { config.allowUnfree = true; }; callPackage ./packages/claude-cli {}'
Verify the version:
./result/bin/claude --version
Clean up the test build:
rm result
4. Deploy
Commit your changes and rebuild:
git add packages/claude-cli/
git commit -m "claude-cli: Update to version X.Y.Z"
darwin-rebuild switch --flake .#blkfv4yf49kt7
Alternative: Automated Hash Fetching
If you prefer to fetch hashes automatically, you can use nix-prefetch-url:
# For macOS ARM64 (your current platform)
nix-prefetch-url "https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases/VERSION/darwin-arm64/claude"
# For other platforms, replace VERSION and adjust the platform string:
# darwin-x64, linux-x64, linux-arm64
This will download the file and output the SHA256 hash.