diff --git a/packages/claude-code/default.nix b/packages/claude-code/default.nix index 4d4a8fc..24437c8 100644 --- a/packages/claude-code/default.nix +++ b/packages/claude-code/default.nix @@ -1,7 +1,8 @@ { lib , stdenv , fetchurl -, autoPatchelfHook +, patchelf +, glibc }: let @@ -38,8 +39,14 @@ in stdenv.mkDerivation { dontUnpack = true; dontBuild = true; + # Bun standalone binaries have JS code appended after the ELF sections + # stripping/patching would remove or corrupt this appended data + dontStrip = true; + dontPatchELF = true; - nativeBuildInputs = lib.optionals stdenv.isLinux [ autoPatchelfHook ]; + # Don't use autoPatchelfHook - it rewrites the ELF and strips the appended + # bun bundle (the JS code is appended after the ELF sections) + nativeBuildInputs = lib.optionals stdenv.isLinux [ patchelf ]; installPhase = '' runHook preInstall @@ -49,6 +56,14 @@ in stdenv.mkDerivation { runHook postInstall ''; + # Manually patch the interpreter for bun standalone binaries + # patchelf --set-interpreter modifies in-place without rewriting the entire ELF, + # preserving the appended JS bundle that bun needs at runtime + postFixup = lib.optionalString stdenv.isLinux '' + interpreter="${glibc}/lib/${if stdenv.hostPlatform.system == "aarch64-linux" then "ld-linux-aarch64.so.1" else "ld-linux-x86-64.so.2"}" + patchelf --set-interpreter "$interpreter" $out/bin/claude + ''; + meta = with lib; { description = "Terminal-based AI coding assistant from Anthropic"; homepage = "https://www.anthropic.com/claude-code";