diff --git a/overlays/unstable/claude-code/manifest.json b/overlays/unstable/claude-code/manifest.json new file mode 100644 index 0000000..774b348 --- /dev/null +++ b/overlays/unstable/claude-code/manifest.json @@ -0,0 +1,47 @@ +{ + "version": "2.1.119", + "commit": "6f68554839756189e277b8285a18fe47acd9a5a1", + "buildDate": "2026-04-23T20:45:14Z", + "platforms": { + "darwin-arm64": { + "binary": "claude", + "checksum": "31db3444309d5d0f8b85e8782e2dcd86f31f7e48c1a1e83d69b09268c7b4f9a2", + "size": 213404000 + }, + "darwin-x64": { + "binary": "claude", + "checksum": "52b3b75cfe80c626982b2ffb3a6ce1c797824f257dc275cf0a3c32c202b6a3df", + "size": 214951760 + }, + "linux-arm64": { + "binary": "claude", + "checksum": "382aa73ea4b07fd8d698e3159b5ef9e1b8739fae7505ba8ddd28b8a6a62819ce", + "size": 245500480 + }, + "linux-x64": { + "binary": "claude", + "checksum": "cca43053f062949495596b11b6fd1b59cf79102adb13bacbe66997e6fae41e4a", + "size": 245230208 + }, + "linux-arm64-musl": { + "binary": "claude", + "checksum": "e09bfaedd8bfdeaebe5f1cf9bb81ebeb718312c68fffce379fb51786263143d0", + "size": 238225856 + }, + "linux-x64-musl": { + "binary": "claude", + "checksum": "ef41a11653b39c14db2d343f1f5e2a3af7eb9871c63e64deb6e65919670a4e0b", + "size": 239495616 + }, + "win32-x64": { + "binary": "claude.exe", + "checksum": "e18c7dcfad4a3f5d33d202ec2dde630b648cf5b41622154d6210e793c7cceadc", + "size": 254478496 + }, + "win32-arm64": { + "binary": "claude.exe", + "checksum": "9e0deb10c45108612484ce558fad378206d5ac23feb203067450e6c38d001241", + "size": 251203232 + } + } +} diff --git a/overlays/unstable/claude-code/package.nix b/overlays/unstable/claude-code/package.nix index 89dc381..ace4105 100644 --- a/overlays/unstable/claude-code/package.nix +++ b/overlays/unstable/claude-code/package.nix @@ -1,57 +1,68 @@ # NOTE: Use the following command to update the package # ```sh -# nix-shell maintainers/scripts/update.nix --argstr commit true --arg predicate '(path: pkg: builtins.elem path [["claude-code"] ["claude-code-bin"] ["vscode-extensions" "anthropic" "claude-code"]])' +# nix-shell maintainers/scripts/update.nix --argstr commit true --arg predicate '(path: pkg: builtins.elem path [["claude-code"] ["vscode-extensions" "anthropic" "claude-code"]])' # ``` { lib, - stdenv, - buildNpmPackage, - fetchzip, + stdenvNoCC, + fetchurl, + installShellFiles, + makeBinaryWrapper, + autoPatchelfHook, + procps, + ripgrep, + bubblewrap, + socat, versionCheckHook, writableTmpDirAsHomeHook, - bubblewrap, - procps, - socat, }: -buildNpmPackage (finalAttrs: { +let + stdenv = stdenvNoCC; + baseUrl = "https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases"; + manifest = lib.importJSON ./manifest.json; + platformKey = "${stdenv.hostPlatform.node.platform}-${stdenv.hostPlatform.node.arch}"; + platformManifestEntry = manifest.platforms.${platformKey}; +in +stdenv.mkDerivation (finalAttrs: { pname = "claude-code"; - version = "2.1.112"; + inherit (manifest) version; - src = fetchzip { - url = "https://registry.npmjs.org/@anthropic-ai/claude-code/-/claude-code-${finalAttrs.version}.tgz"; - hash = "sha256-SJJqU7XHbu9IRGPMJNUg6oaMZiQUKqJhI2wm7BnR1gs="; + src = fetchurl { + url = "${baseUrl}/${finalAttrs.version}/${platformKey}/claude"; + sha256 = platformManifestEntry.checksum; }; - npmDepsHash = "sha256-bdkej9Z41GLew9wi1zdNX+Asauki3nT1+SHmBmaUIBU="; + dontUnpack = true; + dontBuild = true; + __noChroot = stdenv.hostPlatform.isDarwin; + # otherwise the bun runtime is executed instead of the binary + dontStrip = true; + + nativeBuildInputs = [ + installShellFiles + makeBinaryWrapper + ] + ++ lib.optionals stdenv.hostPlatform.isElf [ autoPatchelfHook ]; strictDeps = true; - postPatch = '' - cp ${./package-lock.json} package-lock.json + installPhase = '' + runHook preInstall - # https://github.com/anthropics/claude-code/issues/15195 - substituteInPlace cli.js \ - --replace-fail '#!/bin/sh' '#!/usr/bin/env sh' - ''; + installBin $src - dontNpmBuild = true; - - env.AUTHORIZED = "1"; - - # `claude-code` tries to auto-update by default, this disables that functionality. - # https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview#environment-variables - # The DEV=true env var causes claude to crash with `TypeError: window.WebSocket is not a constructor` - postInstall = '' wrapProgram $out/bin/claude \ --set DISABLE_AUTOUPDATER 1 \ --set-default FORCE_AUTOUPDATE_PLUGINS 1 \ --set DISABLE_INSTALLATION_CHECKS 1 \ - --unset DEV \ + --set USE_BUILTIN_RIPGREP 0 \ --prefix PATH : ${ lib.makeBinPath ( [ # claude-code uses [node-tree-kill](https://github.com/pkrumins/node-tree-kill) which requires procps's pgrep(darwin) or ps(linux) procps + # https://code.claude.com/docs/en/troubleshooting#search-and-discovery-issues + ripgrep ] # the following packages are required for the sandbox to work (Linux only) ++ lib.optionals stdenv.hostPlatform.isLinux [ @@ -60,6 +71,8 @@ buildNpmPackage (finalAttrs: { ] ) } + + runHook postInstall ''; doInstallCheck = true; @@ -68,23 +81,32 @@ buildNpmPackage (finalAttrs: { versionCheckHook ]; versionCheckKeepEnvironment = [ "HOME" ]; + versionCheckProgramArg = "--version"; passthru.updateScript = ./update.sh; meta = { description = "Agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster"; homepage = "https://github.com/anthropics/claude-code"; - downloadPage = "https://www.npmjs.com/package/@anthropic-ai/claude-code"; + downloadPage = "https://claude.com/product/claude-code"; + changelog = "https://github.com/anthropics/claude-code/blob/main/CHANGELOG.md"; license = lib.licenses.unfree; + sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; + platforms = [ + "aarch64-darwin" + "x86_64-darwin" + "aarch64-linux" + "x86_64-linux" + ]; maintainers = with lib.maintainers; [ adeci malo markus1189 + mirkolenz omarjatoi oskarwires xiaoxiangmoe ]; mainProgram = "claude"; - sourceProvenance = with lib.sourceTypes; [ binaryBytecode ]; }; }) diff --git a/overlays/unstable/claude-code/update.sh b/overlays/unstable/claude-code/update.sh index 870f733..1e2125a 100755 --- a/overlays/unstable/claude-code/update.sh +++ b/overlays/unstable/claude-code/update.sh @@ -1,15 +1,12 @@ #!/usr/bin/env nix -#!nix shell --ignore-environment .#cacert .#nodejs .#git .#nix-update .#nix .#gnused .#findutils .#bash --command bash +#!nix shell --ignore-environment .#cacert .#coreutils .#curl .#bash --command bash set -euo pipefail -version=$(npm view @anthropic-ai/claude-code version) +cd "$(dirname "${BASH_SOURCE[0]}")" -# Update version and hashes -AUTHORIZED=1 NIXPKGS_ALLOW_UNFREE=1 nix-update claude-code --version="$version" --generate-lockfile +BASE_URL="https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases" -# nix-update can't update package-lock.json along with npmDepsHash -# TODO: Remove this workaround if nix-update can update package-lock.json along with npmDepsHash. -(nix-build --expr '((import ./.) { system = builtins.currentSystem; }).claude-code.npmDeps.overrideAttrs { outputHash = ""; outputHashAlgo = "sha256"; }' 2>&1 || true) \ -| sed -nE '$s/ *got: *(sha256-[A-Za-z0-9+/=-]+).*/\1/p' \ -| xargs -I{} sed -i 's|npmDepsHash = "sha256-[^"]*";|npmDepsHash = "{}";|' pkgs/by-name/cl/claude-code/package.nix +VERSION="${1:-$(curl -fsSL "$BASE_URL/latest")}" + +curl -fsSL "$BASE_URL/$VERSION/manifest.json" --output manifest.json