Skip to content

Bun version mismatch with nixpkgs causes Nix build failure #15394

@jbotwell

Description

@jbotwell

Description

Note: This as an AI-generated issue, but I have gone over it and it is at least as good as anything I would have managed:

Problem
The Nix flake build fails when nixpkgs has an older Bun version than what's specified in package.json's packageManager field.
error: This script requires bun@^1.3.10, but you are using bun@1.3.9
This occurs because:

  1. The flake uses pkgs.bun from nixpkgs (currently 1.3.9)
  2. package.json specifies "packageManager": "bun@1.3.10"
  3. packages/script/src/index.ts:15 enforces this version at runtime
    Current Behavior
    Users building opencode via the Nix flake are blocked when nixpkgs lags behind the required Bun version.
    Suggested Solutions
    Option 1: Pin Bun version in flake
    Instead of relying on nixpkgs' bun, fetch the specific version:
    bun = pkgs.stdenv.mkDerivation {
    name = "bun-${version}";
    src = pkgs.fetchzip {
    url = "https://github.com/oven-sh/bun/releases/download/bun-v${version}/bun-linux-x64.zip";
    hash = "sha256-...";
    };
    installPhase = "mkdir -p $out/bin && cp bun $out/bin/";
    };
    Option 2: Relax version check for Nix builds
    Make the version check a warning instead of an error, or skip it when NIX_BUILD_TOP is set (indicating a Nix build environment).
    if (!semver.satisfies(process.versions.bun, expectedBunVersionRange)) {
    if (process.env.NIX_BUILD_TOP) {
    console.warn(Warning: Expected bun@${expectedBunVersionRange}, got bun@${process.versions.bun});
    } else {
    throw new Error(This script requires bun@${expectedBunVersionRange}, but you are using bun@${process.versions.bun});
    }
    }
    Workaround
    Users can override bun in their own flake, but this requires maintaining a separate overlay.

Plugins

No response

OpenCode version

1.2.15

Steps to reproduce

nix run github:anomalyco/opencode (commit a94f564)

produces

error: Cannot build '/nix/store/dp9mb7ylrwjx1nmir78204lj1x1cszwi-opencode-1.2.15-a94f564.drv'.
       Reason: builder failed with exit code 1.
       Output paths:
         /nix/store/3zmxsvdf0x7wlaaizbhyp3vjqhlzw3py-opencode-1.2.15-a94f564
       Last 19 log lines:
       > Using versionCheckHook
       > Running phase: unpackPhase
       > unpacking source archive /nix/store/rrr8svra75mrzca0mwq0bhvawn98p4cm-source
       > source root is source
       > Running phase: patchPhase
       > Running phase: updateAutotoolsGnuConfigScriptsPhase
       > Running phase: configurePhase
       > Running phase: buildPhase
       > 11 |
       > 12 | // relax version requirement
       > 13 | const expectedBunVersionRange = `^${expectedBunVersion}`
       > 14 |
       > 15 | if (!semver.satisfies(process.versions.bun, expectedBunVersionRange)) {
       > 16 |   throw new Error(`This script requires bun@${expectedBunVersionRange}, but you are using bun@${process.versions.bun}`)
       >                  ^
       > error: This script requires bun@^1.3.10, but you are using bun@1.3.9
       >       at /build/source/packages/script/src/index.ts:16:13
       >
       > Bun v1.3.9 (Linux x64)
       For full logs, run:
         nix log /nix/store/dp9mb7ylrwjx1nmir78204lj1x1cszwi-opencode-1.2.15-a94f564.drv

Screenshot and/or share link

No response

Operating System

Nixos 25.11

Terminal

Ghostty

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingnix

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions