From 53e3bbe78fbefbd09460577ae539647c758150aa Mon Sep 17 00:00:00 2001 From: mayor Date: Mon, 19 Jan 2026 10:39:58 -0800 Subject: [PATCH] fix(claude-code): preserve bun appended bundle during NixOS build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bun standalone executables store their JavaScript code by appending it after the ELF sections, marked with "---- Bun! ----". The standard Nix build process was corrupting this: - autoPatchelfHook rewrites the entire ELF, losing appended data - strip removes data after ELF sections - patchelf shrink-rpath also rewrites the ELF Fix by: - Using dontStrip and dontPatchELF to skip automatic fixup - Manually running patchelf --set-interpreter which modifies in-place without rewriting the entire file structure This restores the binary from 99MB (bare bun runtime) to 220MB (full claude-code application). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Executed-By: mayor Role: mayor --- packages/claude-code/default.nix | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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";