fix(nix): replace manual hash management with bun2nix#1021
fix(nix): replace manual hash management with bun2nix#1021cjpais merged 6 commits intocjpais:mainfrom
Conversation
Eliminate the recurring problem of Nix build hashes breaking whenever bun dependencies change or the bun version in nixpkgs updates. Changes: - Add bun2nix flake input (pinned to v2.0.1) for per-package fetchurl expressions from bun.lock, replacing the single FOD hash approach - Use allowBuiltinFetchGit for cargo git dependencies, removing manual outputHashes that required updates on every git dep change - Add scripts/check-nix-deps.ts (cross-platform, runs via bun) that auto-regenerates .nix/bun.nix when bun.lock changes, triggered by the postinstall hook in package.json - Update CI workflow to verify bun.nix is in sync and evaluate flake - Remove scripts/update-nix-hashes.sh (no longer needed)
|
@CaptainSpof @pomarec @kakapt @y0usaf please verify |
|
Confirmed, builds on my system. |
| writeFileSync(hashFile, currentHash + "\n"); | ||
| console.log(`[check-nix-deps] Updated ${nixFile}`); | ||
| console.log( | ||
| "[check-nix-deps] Don't forget to commit: .nix/bun.nix .nix/bun-lock-hash", |
There was a problem hiding this comment.
process.exit(1) blocks bun install for non-Nix devs when bun2nix fails. Since CI validates bun.nix independently, this should be process.exit(0) with a warning.
- Fix bun2nix input pinning: use path syntax (github:owner/repo/tag) instead of ?tag= query parameter so flake.lock records the ref and `nix flake update` respects the pin - Make check-nix-deps.ts exit with 0 on bun2nix failure so that `bun install` is not blocked for non-Nix developers (CI validates bun.nix independently) - Fix stale reference to check-nix-deps.sh in flake.nix comment
|
It fails to build on my system: Output of |
Add `nix build .#handy -L --show-trace` after flake evaluation to catch runtime build errors (broken dependencies, sandbox issues, compilation failures) that flake eval alone cannot detect.
bun2nix 2.0.1 has a bug in cache-entry-creator that causes "ln: failed to create symbolic link '/p': Permission denied" during the build. Version 2.0.8 fixes this.
🧪 Test Build ReadyBuild artifacts for PR #1021 are available for testing. Download artifacts from workflow run Artifacts expire after 30 days. |
|
LGTM I confirm that |
|
Okay everyone seems to be happy with it, to be honest I'm not going to read the changes. But you NixOS folks are so responsive. More responsive than any other community. Mad respect. I expect y'all will continue to fix issues as they come up. If you need me to do something in particular just let me know |
Please confirm you have done the following:
requests (including closed ones) to ensure this isn't a duplicate
If this is a feature or change that was previously closed/rejected:
Human Written Description
The Nix build (
nix build .#handy) keeps breaking because the fixed-output derivationhash for bun dependencies has to be manually updated every time
bun.lockchanges.The same problem exists for cargo git dependency hashes. This makes maintaining the Nix
package tedious and results in frequent hash-update PRs.
This PR eliminates all manual hash management by switching to bun2nix (per-package
fetchurl expressions) for bun deps and
allowBuiltinFetchGitfor cargo git deps.A postinstall hook auto-regenerates the Nix files whenever
bun.lockchanges, sonon-Nix developers won't accidentally break the Nix build.
Normally, when you update TS dependencies with
bun add ...orbun update ..., Nix dependency files are auto-updated via the postinstall hook.A developer just needs to commit the updated files, same as with
Cargo.lock.If
bun.lockis updated manually (without bun), the CI jobnix build checkwill catch itand show a red status with an error message explaining that you should run
bun scripts/check-nix-deps.tsto update Nix dependencies.I believe this should eliminate 99% of problems with Nix dependencies.
After this PR, manual fixes are only expected when
ferrous-openccis updated(it requires a special patch currently), or if you decide to publish the app in
nixpkgs (which prohibits
allowBuiltinFetchGit— but for standalone flake packagesit's fine). In all other cases, Nix dependencies should be updated automatically
via the hook or by running the script in the same PR where the bun dependency changed,
without requiring a separate manual PR.
Note: The
nix build checkCI job is currently set tocontinue-on-error: false,meaning it will block PRs with outdated Nix files. The fix is always straightforward
(just run
bun installorbun scripts/check-nix-deps.ts), but if you'd preferthis check to be non-blocking, simply change it to
continue-on-error: truein.github/workflows/nix-check.yml.Note 2: The CI job now performs a full
nix build .#handyin addition to dependency syncand flake evaluation, to catch runtime build errors. This takes ~27 min on a cold cache.
In the future, this could potentially be reduced to ~5 min by adding
Cachix (requires an account and setup; the estimate is based on
the assumption that only changed derivations would be rebuilt, similar to how
rust-cacheworks for cargo in the
rust-testsjob).@cjpais For this PR, you can choose:
Build handystep, keeping only the dependencysync check + flake evaluation (~30s), which still catches most issues
Related Issues/Discussions
Supersedes the manual hash update approach from #948.
Community Feedback
This is a fix for a recurring maintenance burden that has required multiple PRs just to update hashes. It doesn't add any new features.
Testing
nix eval .#packages.x86_64-linux.handy.drvPath— flake evaluation passesnix build .#handy— full build succeedsbun installtriggerspostinstallhook and regenerates.nix/bun.nixwhenbun.lockchangesbun.lockis unchanged (~2ms check)Screenshots/Videos (if applicable)
N/A
AI Assistance
If AI was used: