Rename claude-cli package to claude-code for consistency with nixpkgs
This commit is contained in:
116
packages/claude-code/README.md
Normal file
116
packages/claude-code/README.md
Normal file
@@ -0,0 +1,116 @@
|
||||
# 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:
|
||||
|
||||
```bash
|
||||
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:
|
||||
|
||||
```bash
|
||||
./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:
|
||||
|
||||
```bash
|
||||
curl -s "https://raw.githubusercontent.com/Homebrew/homebrew-cask/HEAD/Casks/c/claude-code.rb" | head -50
|
||||
```
|
||||
|
||||
This will show:
|
||||
- The latest `version` number
|
||||
- SHA256 hashes for all platforms (`arm64`, `x86_64`, `x86_64_linux`, `arm64_linux`)
|
||||
|
||||
#### 2. Update default.nix
|
||||
|
||||
Edit `default.nix` and update:
|
||||
|
||||
1. The `version` variable (line 9):
|
||||
```nix
|
||||
version = "2.0.51"; # Update this
|
||||
```
|
||||
|
||||
2. All four platform sha256 hashes in the `srcs` attribute set (lines 11-27):
|
||||
```nix
|
||||
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:
|
||||
|
||||
```bash
|
||||
NIXPKGS_ALLOW_UNFREE=1 nix-build -E 'with import <nixpkgs> { config.allowUnfree = true; }; callPackage ./packages/claude-cli {}'
|
||||
```
|
||||
|
||||
Verify the version:
|
||||
|
||||
```bash
|
||||
./result/bin/claude --version
|
||||
```
|
||||
|
||||
Clean up the test build:
|
||||
|
||||
```bash
|
||||
rm result
|
||||
```
|
||||
|
||||
#### 4. Deploy
|
||||
|
||||
Commit your changes and rebuild:
|
||||
|
||||
```bash
|
||||
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`:
|
||||
|
||||
```bash
|
||||
# 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.
|
||||
60
packages/claude-code/default.nix
Normal file
60
packages/claude-code/default.nix
Normal file
@@ -0,0 +1,60 @@
|
||||
{ lib
|
||||
, stdenv
|
||||
, fetchurl
|
||||
, autoPatchelfHook
|
||||
}:
|
||||
|
||||
let
|
||||
version = "2.0.53";
|
||||
|
||||
srcs = {
|
||||
aarch64-darwin = {
|
||||
url = "https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases/${version}/darwin-arm64/claude";
|
||||
sha256 = "28c3ad73a20f3ae7ab23efa24d45a9791ccbe071284f1622d4e5e2b89c4a15b7";
|
||||
};
|
||||
x86_64-darwin = {
|
||||
url = "https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases/${version}/darwin-x64/claude";
|
||||
sha256 = "a27f7b75a51514658640432a0afec8be130673eb7dbecc9a4d742527dd85d29a";
|
||||
};
|
||||
x86_64-linux = {
|
||||
url = "https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases/${version}/linux-x64/claude";
|
||||
sha256 = "9c4cc19e207fb6bf7ea140a1580d5ed0dd0a481af471f23614d5a140a4abf1c6";
|
||||
};
|
||||
aarch64-linux = {
|
||||
url = "https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases/${version}/linux-arm64/claude";
|
||||
sha256 = "a5d4044034f3b63c38379bc2dd4067a4dd3c8ec48965ba8e66e3623774a93b72";
|
||||
};
|
||||
};
|
||||
|
||||
src = srcs.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
|
||||
|
||||
in stdenv.mkDerivation {
|
||||
pname = "claude-code";
|
||||
inherit version;
|
||||
|
||||
src = fetchurl {
|
||||
inherit (src) url sha256;
|
||||
};
|
||||
|
||||
dontUnpack = true;
|
||||
dontBuild = true;
|
||||
|
||||
nativeBuildInputs = lib.optionals stdenv.isLinux [ autoPatchelfHook ];
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
install -Dm755 $src $out/bin/claude
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
meta = with lib; {
|
||||
description = "Terminal-based AI coding assistant from Anthropic";
|
||||
homepage = "https://www.anthropic.com/claude-code";
|
||||
license = licenses.unfree;
|
||||
maintainers = [ ];
|
||||
platforms = [ "aarch64-darwin" "x86_64-darwin" "x86_64-linux" "aarch64-linux" ];
|
||||
mainProgram = "claude";
|
||||
};
|
||||
}
|
||||
34
packages/claude-code/npm.nix
Normal file
34
packages/claude-code/npm.nix
Normal file
@@ -0,0 +1,34 @@
|
||||
{ lib
|
||||
, buildNpmPackage
|
||||
, fetchurl
|
||||
, nodejs_18
|
||||
}:
|
||||
|
||||
buildNpmPackage {
|
||||
pname = "claude-cli";
|
||||
version = "0.2.65";
|
||||
|
||||
src = fetchurl {
|
||||
url = "https://registry.npmjs.org/@anthropic-ai/claude-code/-/claude-code-0.2.65.tgz";
|
||||
sha256 = "0wwaqq7k9p5aw4vqhfpdgf3da09x64q55wibqaprk6kjvn130i92";
|
||||
};
|
||||
|
||||
npmDepsHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; # Will be updated after first build
|
||||
|
||||
nodejs = nodejs_18;
|
||||
|
||||
# Don't run npm audit or other network operations during build
|
||||
npmConfigHook = ''
|
||||
npm config set audit false
|
||||
npm config set fund false
|
||||
'';
|
||||
|
||||
meta = with lib; {
|
||||
description = "Terminal-based AI coding assistant from Anthropic (npm distribution)";
|
||||
homepage = "https://www.anthropic.com/claude-code";
|
||||
license = licenses.unfree;
|
||||
maintainers = [ ];
|
||||
platforms = platforms.all;
|
||||
mainProgram = "claude";
|
||||
};
|
||||
}
|
||||
132
packages/claude-code/update.sh
Executable file
132
packages/claude-code/update.sh
Executable file
@@ -0,0 +1,132 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
DRY_RUN=false
|
||||
|
||||
# Parse arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
--dry-run|-n)
|
||||
DRY_RUN=true
|
||||
shift
|
||||
;;
|
||||
--help|-h)
|
||||
echo "Usage: $0 [OPTIONS]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " --dry-run, -n Show what would be updated without making changes"
|
||||
echo " --help, -h Show this help message"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
echo "Use --help for usage information"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
CASK_URL="https://raw.githubusercontent.com/Homebrew/homebrew-cask/HEAD/Casks/c/claude-code.rb"
|
||||
NIX_FILE="$(dirname "$0")/default.nix"
|
||||
|
||||
echo "Fetching latest claude-code version from Homebrew cask..."
|
||||
|
||||
# Fetch the cask file
|
||||
CASK_CONTENT=$(curl -fsSL "$CASK_URL")
|
||||
|
||||
# Extract version (format: version "X.Y.Z")
|
||||
NEW_VERSION=$(echo "$CASK_CONTENT" | grep -m1 'version' | sed -E 's/.*version "([^"]+)".*/\1/')
|
||||
|
||||
# Extract SHA256 hashes (be specific to match sha256 lines only)
|
||||
SHA_ARM=$(echo "$CASK_CONTENT" | grep 'sha256 arm:' | sed -E 's/.*"([a-f0-9]{64})".*/\1/')
|
||||
SHA_X86_64=$(echo "$CASK_CONTENT" | grep 'x86_64:' | sed -E 's/.*"([a-f0-9]{64})".*/\1/')
|
||||
SHA_X86_64_LINUX=$(echo "$CASK_CONTENT" | grep 'x86_64_linux:' | sed -E 's/.*"([a-f0-9]{64})".*/\1/')
|
||||
SHA_ARM64_LINUX=$(echo "$CASK_CONTENT" | grep 'arm64_linux:' | sed -E 's/.*"([a-f0-9]{64})".*/\1/')
|
||||
|
||||
# Get current version
|
||||
CURRENT_VERSION=$(grep -m1 'version = ' "$NIX_FILE" | sed -E 's/.*version = "([^"]+)".*/\1/')
|
||||
|
||||
# Validate extracted data
|
||||
if [ -z "$NEW_VERSION" ] || [ -z "$SHA_ARM" ] || [ -z "$SHA_X86_64" ] || [ -z "$SHA_X86_64_LINUX" ] || [ -z "$SHA_ARM64_LINUX" ]; then
|
||||
echo -e "${RED}Error: Failed to extract all required values from Homebrew cask${NC}"
|
||||
echo "Version: $NEW_VERSION"
|
||||
echo "ARM: $SHA_ARM"
|
||||
echo "x86_64: $SHA_X86_64"
|
||||
echo "x86_64_linux: $SHA_X86_64_LINUX"
|
||||
echo "arm64_linux: $SHA_ARM64_LINUX"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if update is needed
|
||||
if [ "$CURRENT_VERSION" = "$NEW_VERSION" ]; then
|
||||
echo -e "${GREEN}Already up to date: $CURRENT_VERSION${NC}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo -e "${YELLOW}Updating from $CURRENT_VERSION to $NEW_VERSION${NC}"
|
||||
|
||||
if [ "$DRY_RUN" = true ]; then
|
||||
echo -e "${YELLOW}DRY RUN - No changes will be made${NC}"
|
||||
echo ""
|
||||
echo "Would update:"
|
||||
echo " Version: $CURRENT_VERSION -> $NEW_VERSION"
|
||||
echo " aarch64-darwin SHA: $SHA_ARM"
|
||||
echo " x86_64-darwin SHA: $SHA_X86_64"
|
||||
echo " x86_64-linux SHA: $SHA_X86_64_LINUX"
|
||||
echo " aarch64-linux SHA: $SHA_ARM64_LINUX"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Update version
|
||||
sed -i.tmp "s/version = \".*\";/version = \"$NEW_VERSION\";/" "$NIX_FILE"
|
||||
|
||||
# Update SHA256 hashes using awk for more reliable parsing
|
||||
awk -v sha_arm="$SHA_ARM" -v sha_x86="$SHA_X86_64" -v sha_x86_linux="$SHA_X86_64_LINUX" -v sha_arm_linux="$SHA_ARM64_LINUX" '
|
||||
/aarch64-darwin = {/ { in_arm = 1 }
|
||||
/x86_64-darwin = {/ { in_x86 = 1 }
|
||||
/x86_64-linux = {/ { in_x86_linux = 1 }
|
||||
/aarch64-linux = {/ { in_arm_linux = 1 }
|
||||
/};/ {
|
||||
in_arm = 0
|
||||
in_x86 = 0
|
||||
in_x86_linux = 0
|
||||
in_arm_linux = 0
|
||||
}
|
||||
/sha256 = / {
|
||||
if (in_arm) {
|
||||
sub(/sha256 = ".*";/, "sha256 = \"" sha_arm "\";")
|
||||
} else if (in_x86) {
|
||||
sub(/sha256 = ".*";/, "sha256 = \"" sha_x86 "\";")
|
||||
} else if (in_x86_linux) {
|
||||
sub(/sha256 = ".*";/, "sha256 = \"" sha_x86_linux "\";")
|
||||
} else if (in_arm_linux) {
|
||||
sub(/sha256 = ".*";/, "sha256 = \"" sha_arm_linux "\";")
|
||||
}
|
||||
}
|
||||
{ print }
|
||||
' "$NIX_FILE" > "$NIX_FILE.new"
|
||||
|
||||
mv "$NIX_FILE.new" "$NIX_FILE"
|
||||
|
||||
# Clean up temp files
|
||||
rm -f "$NIX_FILE.tmp"
|
||||
|
||||
echo -e "${GREEN}Successfully updated to version $NEW_VERSION${NC}"
|
||||
echo ""
|
||||
echo "Updated SHA256 hashes:"
|
||||
echo " aarch64-darwin: $SHA_ARM"
|
||||
echo " x86_64-darwin: $SHA_X86_64"
|
||||
echo " x86_64-linux: $SHA_X86_64_LINUX"
|
||||
echo " aarch64-linux: $SHA_ARM64_LINUX"
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo " 1. Review changes: git diff $NIX_FILE"
|
||||
echo " 2. Test build: NIXPKGS_ALLOW_UNFREE=1 nix-build -E 'with import <nixpkgs> { config.allowUnfree = true; }; callPackage ./packages/claude-code {}'"
|
||||
echo " 3. Verify version: ./result/bin/claude --version"
|
||||
echo " 4. Commit: git add $NIX_FILE && git commit -m 'claude-code: Update to version $NEW_VERSION'"
|
||||
Reference in New Issue
Block a user