---
id: BACK-210
title: Refactor Nix packaging to build node_modules offline
status: Done
assignee: []
created_date: '2025-07-26'
updated_date: '2025-07-31'
labels:
  - nix
  - build
  - packaging
dependencies: []
---

## Description

Our current flake.nix runs 'bun install' inside the Nix build. Nix builds run without internet access, so trying to download tailwindcss and other dependencies in the build causes a 'connection refused' error. We need to refactor the Nix packaging to use bun2nix for native Bun lockfile support instead of maintaining dual lockfiles (bun.lock + package-lock.json).

## Acceptance Criteria

- [x] The Nix flake uses bun2nix to generate dependencies from bun.lock instead of requiring separate package-lock.json
- [x] nix build succeeds in a clean sandbox (no network access) and produces a working backlog binary
- [x] nix run . -- --version prints the CLI version without errors on supported platforms  
- [x] Only bun.lock is used for dependency management (no package-lock.json maintenance required)
- [x] Documentation in README or a scripts/ helper explains how to update dependencies when bun.lock changes

## Implementation Plan

1. Research bun2nix integration patterns and current status
2. Add bun2nix as flake input and configure mkBunPackage
3. Remove generated package-lock.json and revert to native Bun approach
4. Test build works correctly in sandbox environment
5. Update documentation for dependency management workflow

## Implementation Notes

Refactored Nix packaging to use bun2nix instead of the npm-based approach from PR #260. This eliminates the need to maintain dual lockfiles and provides native Bun ecosystem support.

Key changes:
- Added bun2nix flake input from github:baileyluTCD/bun2nix  
- Replaced `pkgs.stdenv.mkDerivation` with `bun2nix.lib.${system}.mkBunDerivation`
- Configured to use existing `bun.lock` and `package.json` directly without requiring package-lock.json
- Removed network-dependent `bun install --frozen-lockfile` from build process
- Added comprehensive Nix installation documentation to README

The solution provides offline builds using bun2nix's dependency resolution while maintaining the existing Bun-based development workflow. Dependencies are now fetched in a separate derivation and cached, enabling reproducible builds in sandboxed environments.
