Skip to content

docs(nixos): add Bun SEA binary packaging guide#183

Open
heath-hunnicutt-ruach-tov wants to merge 1 commit intoandrewyng:mainfrom
heath-hunnicutt-ruach-tov:nixos/bun-sea-packaging
Open

docs(nixos): add Bun SEA binary packaging guide#183
heath-hunnicutt-ruach-tov wants to merge 1 commit intoandrewyng:mainfrom
heath-hunnicutt-ruach-tov:nixos/bun-sea-packaging

Conversation

@heath-hunnicutt-ruach-tov
Copy link
Copy Markdown

Summary

Adds a new context document explaining how to package Bun SEA (Single Executable Application) binaries on NixOS.

The Problem

Bun SEA binaries embed compiled JavaScript bytecode appended after the ELF section table. NixOS's autoPatchelfHook rewrites the ELF structure, truncating this appended data and breaking the binary. The packaged binary acts as a bare Bun runtime instead of the intended application.

What This Doc Covers

  • Root cause analysis (appended bytecode + ---- Bun! ---- sentinel)
  • Why autoPatchelfHook breaks it (ELF rewrite truncates appended data)
  • Why makeWrapper with ld-linux doesn't work (/proc/self/exe mismatch)
  • Working fix: patchelf --set-interpreter (preserves appended data)
  • Complete Nix derivation template with build-time sentinel verification
  • Checklist of safe/unsafe ELF operations

Discovery

Found while packaging varlock for NixOS (March 2026). This is a general class of NixOS packaging bug that affects any Bun-compiled binary, not just varlock.

Files

  • content/nixos/docs/bun-sea-packaging/DOC.md — new doc

Checklist

  • YAML frontmatter with required fields (name, description, metadata.tags, updated-on, source)
  • Content written for LLM consumption (clear structure, code examples)
  • Practical, tested solution (verified on NixOS 24.11)

Bun SEA (Single Executable Application) binaries store compiled JavaScript
bytecode appended after the ELF section table. NixOS's autoPatchelfHook
truncates this data, breaking the binary. This doc explains the root cause
and provides a working Nix derivation pattern using patchelf --set-interpreter.

Discovered while packaging varlock for NixOS (March 2026).

Tags: nixos, nix, bun, packaging, patchelf, autoPatchelfHook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant