fix(claude-code): preserve bun appended bundle during NixOS build
All checks were successful
CI / check (push) Successful in 3m32s
All checks were successful
CI / check (push) Successful in 3m32s
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 <noreply@anthropic.com> Executed-By: mayor Role: mayor
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
{ lib
|
{ lib
|
||||||
, stdenv
|
, stdenv
|
||||||
, fetchurl
|
, fetchurl
|
||||||
, autoPatchelfHook
|
, patchelf
|
||||||
|
, glibc
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
@@ -38,8 +39,14 @@ in stdenv.mkDerivation {
|
|||||||
|
|
||||||
dontUnpack = true;
|
dontUnpack = true;
|
||||||
dontBuild = 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 = ''
|
installPhase = ''
|
||||||
runHook preInstall
|
runHook preInstall
|
||||||
@@ -49,6 +56,14 @@ in stdenv.mkDerivation {
|
|||||||
runHook postInstall
|
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; {
|
meta = with lib; {
|
||||||
description = "Terminal-based AI coding assistant from Anthropic";
|
description = "Terminal-based AI coding assistant from Anthropic";
|
||||||
homepage = "https://www.anthropic.com/claude-code";
|
homepage = "https://www.anthropic.com/claude-code";
|
||||||
|
|||||||
Reference in New Issue
Block a user