Skip to content
Agentmart
Submit a tool

nix-bun

Use this when building a Bun (bun.lock) project with Nix.

Skill by juspay

IndexedMIT★ 11
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/juspay-nix-bun

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Use this when building a Bun (bun.lock) project with Nix. Covers bun2nix, the bun.nix dependency workflow, the bun --compile top-level-await pitfall, and a CI drift check.

Use cases: devops, productivity

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/nix-bun

What's inside

Skill name
nix-bun
Description
Use this when building a Bun (bun.lock) project with Nix. Covers bun2nix, the bun.nix dependency workflow, the bun --compile top-level-await pitfall, and a CI drift check.
License
MIT
Instructions
71 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# Bun + Nix with bun2nix

For Bun projects (those with a `bun.lock`), use [bun2nix](https://github.com/nix-community/bun2nix) — it converts the lockfile into a `bun.nix` expression so Nix installs dependencies deterministically and offline. Keep nixpkgs pinned via npins (see `nix-for-dev`) and add bun2nix as the single flake input.

## Dependency workflow

`bun.nix` is generated and must track `bun.lock`. Regenerate it whenever dependencies change:

```bash
nix run github:nix-community/bun2nix -- -o bun.nix
```

Pin the same bun2nix version in `flake.nix` (`?ref=2.1.0`) and in CI so generation is reproducible.

## Building

Idiomatic usage compiles a standalone binary:

```nix
# default.nix
{ bun2nix, ... }:
bun2nix.mkDerivation {
  pname = "myapp";
  version = "1.0.0";
  src = ./.;
  bunDeps = bun2nix.fetchBunDeps { bunNix = ./bun.nix; };
  module = "src/index.ts";   # entrypoint compiled into `bin/myapp`
}
```

`bun2nix.packages.<system>.default` carries `mkDerivation`, `fetchBunDeps`, and `hook` as passthru attrs, so you can use it without a flake-parts overlay.

### Pitfall: `bun build --compile` is fragile

`mkDerivation { module = ...; }` runs `bun build --compile`, which **fails on top-level `await`** (`error: "await" can only be used inside an "async" function`) and can produce a broken binary for apps with **native addons or workers**. (`bun run` handles all of these — only the bundler chokes.)

When `--compile` doesn't work, build a wrapper that runs the entrypoint with `bun` instead, using bun2nix only for deterministic deps:

```nix
{ pkgs, bun2nix, ... }:
pkgs.stdenv.mkDerivation {
  pname = "myapp"; version = "1.0.0"; src = ./.;
  nativeBuildInputs = [ bun2nix.hook pkgs.makeWrapper ];  # hook populates node_modules offline
  bunDeps = bun2nix.fetchBunDeps { bunNix = ./bun.nix; };
  # buildPhase: build any workspace deps (tsc) the entrypoint imports
  installPhase = ''
    appdir=$out/share/myapp
    mkdir -p $appdir $out/bin
    cp -R src package.json node_modules $appdir/
    makeWrapper ${pkgs.bun}/bin/bun $out/bin/myapp --add-flags "run $appdir/src/index.ts"
  '';
  dontFixup = true;
}
```

The bun2nix hook runs `patchShebangs`, but tsc's `/usr/bin/env node` shebang still breaks in the sandbox — invoke it as `bun ./node_modules/typescript/bin/tsc` instead of via the `.bin` symlink.

## CI: keep bun.nix from drifting

Add a check that fails when `bun.nix` is out of sync with `bun.lock`:

```yaml
- run: |
    nix run github:nix-community/bun2nix/2.1.0 -- --lock-file ./bun.lock --output-file ./bun.nix
    git diff --exit-code -- bun.nix \
      || { echo "::error::bun.nix is stale — run: nix run github:nix-community/bun2nix -- -o bun.nix"; exit 1; }
```

This check is fast; run it as a separate job from the (slow) `nix build` so PRs get quick feedback. For the build job, cache `/nix/store` — see `nix-ci`.

From juspay/skills, MIT.

More from juspay/skills

Signals

Stars
11
Forks
0
Open issues
3
Last commit (this folder)
Jun 15, 2026 (4 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from juspay

Cite this page

nix-bun skill. Agent Mart. https://agentmart.dev/skills/juspay-nix-bun (last updated 2026-10-24)