Skip to content

chore(nix): add bun node_modules normalization scripts#1256

Open
xilec wants to merge 1 commit intocjpais:mainfrom
xilec:nix/add-bun-normalize-scripts
Open

chore(nix): add bun node_modules normalization scripts#1256
xilec wants to merge 1 commit intocjpais:mainfrom
xilec:nix/add-bun-normalize-scripts

Conversation

@xilec
Copy link
Copy Markdown
Contributor

@xilec xilec commented Apr 8, 2026

Summary

Added two TypeScript scripts to .nix/scripts/ that canonicalize bun's internal symlinks inside node_modules/.bun/:

  • canonicalize-node-modules.ts — rebuilds node_modules/.bun/node_modules/ symlinks in deterministic sorted order
  • normalize-bun-binaries.ts — rebuilds .bin/ symlinks deterministically based on package.json bin fields

Adapted from the opencode package (MIT license).

Why

These scripts are needed for the nixpkgs upstream packaging. Unlike the flake, nixpkgs can't use external tools like bun2nix (it's not merged yet), so the package uses a workaround: bun install --cpu="*" --os="*" to download all platform variants and get a single hash that works on both Linux and macOS. Bun creates symlinks in non-deterministic order which breaks reproducibility — these scripts fix that.

Having them in the Handy repo (rather than in the nixpkgs tree) is the preferred approach, same as opencode does it.

Test plan

  • Scripts are only used during Nix builds, no impact on regular development
  • Verified in nixpkgs build: FOD hash is stable, Handy builds and runs correctly

Add canonicalize-node-modules.ts and normalize-bun-binaries.ts to
.nix/scripts/ for use by nixpkgs and other non-flake Nix builds.

These scripts ensure deterministic symlink ordering inside
node_modules/.bun/, which is required for reproducible fixed-output
derivation hashes when using bun install --cpu="*" --os="*" to fetch
all platform variants.

Adapted from the opencode package (MIT license).
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