fix(nix): use lock-driven Bun dependency fetching for frontend builds#198
fix(nix): use lock-driven Bun dependency fetching for frontend builds#198skulldogged wants to merge 4 commits intospacedriveapp:mainfrom
Conversation
Replace the fixed-output node_modules hash flow with bun2nix lock ingestion so frontend dependency updates no longer require manual Nix hash edits. Add a lock integrity check to fail when bun.lock contains empty integrity entries.
Regenerate the frontend Bun lockfile using the hoisted linker mode used by the Nix bun2nix hook so frozen installs do not attempt lockfile edits during builds.
WalkthroughAdds bun2nix to the flake and wiring in nix/default.nix to replace in-tree Bun handling with bun2nix-generated Bun derivations; exposes bun2nix in spacebotPackages and adds a frontend lock integrity check that inspects Changes
Sequence Diagram(s)sequenceDiagram
participant Flake as flake.nix
participant Bun2Nix as bun2nix (flake input)
participant Generator as generatedFrontendBunNix
participant Fetcher as frontendBunDeps
participant Frontend as frontend derivation
participant Check as frontendLockIntegrityCheck
Flake->>Bun2Nix: expose bun2nix in outputs
Bun2Nix->>Generator: generate Nix expr from bun.lock
Generator->>Fetcher: produce bunDeps derivation
Fetcher->>Frontend: provide bunDeps + bunInstallFlags
Frontend->>Frontend: run bun install (with bunDeps) and bun run build
Check->>Frontend: read bun.lock and run integrity check
Check-->>Flake: report pass/fail
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Co-authored-by: tembo[bot] <208362400+tembo[bot]@users.noreply.github.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
flake.nix (1)
92-100: Defensive improvements for the integrity check: consider handling missing fields and better error reporting.While the current code works correctly for the existing bun.lock (all 850 packages have valid SHA512 hashes at index 3), it's worth adding a defensive check for missing integrity fields and logging affected package names for faster debugging.
Suggested improvement
- const packageEntries = Object.values(lock.packages ?? {}) - const emptyIntegrities = packageEntries.filter( - (entry) => Array.isArray(entry) && entry[3] === "" + const packageMap = lock.packages ?? {} + const emptyIntegrities = Object.entries(packageMap).filter( + ([, entry]) => Array.isArray(entry) && (!entry[3] || entry[3] === "") ) if (emptyIntegrities.length > 0) { - console.error("bun.lock has " + emptyIntegrities.length + " packages with empty integrity hashes") + console.error("bun.lock has " + emptyIntegrities.length + " packages with empty/missing integrity hashes:") + emptyIntegrities.forEach(([name]) => console.error(" - " + name)) process.exit(1) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@flake.nix` around lines 92 - 100, The integrity check currently uses packageEntries = Object.values(lock.packages ?? {}) and only filters Array entries with entry[3] === "", which misses entries with missing fields and doesn't report package names; change to iterate Object.entries(lock.packages ?? {}) so you have both packageName and entry, treat non-array entries or entries.length <= 3 or entry[3] falsy as failures, collect the package names into a list (e.g., badPackages) and update the console.error to include the count and the affected package names (and then process.exit(1) as before) so failures are clearly identified for debugging; reference the variables packageEntries, lock.packages, emptyIntegrities and the exit behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@flake.nix`:
- Around line 92-100: The integrity check currently uses packageEntries =
Object.values(lock.packages ?? {}) and only filters Array entries with entry[3]
=== "", which misses entries with missing fields and doesn't report package
names; change to iterate Object.entries(lock.packages ?? {}) so you have both
packageName and entry, treat non-array entries or entries.length <= 3 or
entry[3] falsy as failures, collect the package names into a list (e.g.,
badPackages) and update the console.error to include the count and the affected
package names (and then process.exit(1) as before) so failures are clearly
identified for debugging; reference the variables packageEntries, lock.packages,
emptyIntegrities and the exit behavior.
Summary
node_moduleshash flow innix/default.nixwith a Bun-native dependency flow driven directly frominterface/bun.lockbun2nixas a flake input and wirefetchBunDeps+bun2nix.hookinto the frontend buildfrontendLockIntegrityCheckinflake.nixto fail whenbun.lockcontains empty integrity entriesinterface/bun.lockso it is compatible with frozen installs in the same linker mode used by the Nix build (--linker=hoisted)Why
Why the lockfile regeneration is needed
--frozen-lockfile, so any lockfile delta causes a hard failureValidation
nix build .#frontendnix build .#checks.x86_64-linux.frontendLockIntegrityCheckNote
Automated Summary
This PR replaces Spacebot's frontend dependency management with a lock-file-driven Nix build that reads directly from
bun.lockviabun2nix. The changes integrate thefetchBunDepshook and add a lockfile integrity check to prevent empty entries. Thebun.lockhas been regenerated with--linker=hoistedto ensure frozen installs work correctly in Nix builds. This eliminates manual hash management in Nix when dependencies change while maintaining reproducibility.Written by Tembo for commit 39830fb. This will update automatically on new commits.