Skip to content

Nix build fails: build.ts fetches from network instead of using MODELS_DEV_API_JSON #10429

Closed

Description

@dlukegordon

Description

The Nix package build fails because packages/opencode/script/build.ts attempts to fetch https://models.dev/api.json during the build phase. Nix builds are sandboxed without network access, causing the build to fail.

Running phase: buildPhase
opencode script {
  "channel": "local",
  "version": "1.1.34-e3c1861",
  "preview": true
}
error: Unable to connect. Is the computer able to access the url?
  path: "https://models.dev/api.json",
 errno: 0,
  code: "ConnectionRefused"

Root Cause

In #9032, nix/opencode.nix was updated to set env.MODELS_DEV_API_JSON with the path to a pre-fetched models-dev derivation:

env.MODELS_DEV_API_JSON = "${models-dev}/dist/_api.json";

However, build.ts doesn't use this environment variable. It unconditionally fetches from the network:

// build.ts lines 17-22
const modelsData = await fetch(`https://models.dev/api.json`).then((x) => x.text())
await Bun.write(
  path.join(dir, "src/provider/models-snapshot.ts"),
  `// Auto-generated by build.ts - do not edit\nexport const snapshot = ${modelsData} as const\n`,
)

Suggested fix

Modify build.ts to check for the environment variable first:

const modelsData = process.env.MODELS_DEV_API_JSON
  ? await Bun.file(process.env.MODELS_DEV_API_JSON).text()
  : await fetch(`https://models.dev/api.json`).then((x) => x.text())

Workaround

Pinning the flake input to a commit before #9032 (e.g., 6e020ef) avoids the issue.

Plugins

No response

OpenCode version

e3c1861

Steps to reproduce

  1. Add opencode flake to your nixos flake.nix:
opencode.url = "github:anomalyco/opencode";
  1. Add opencode package:
  environment.systemPackages = with pkgs; [
    inputs.opencode.packages.${pkgs.stdenv.hostPlatform.system}.default
  ];
  1. Run nixos-switch
sudo nixos-rebuild switch

Screenshot and/or share link

No response

Operating System

NixOS 25.11

Terminal

Ghostty

Activity

  1. github-actions commented on Jan 24, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  2. thdxr commented on Jan 24, 2026

    @thdxr
    Member

    sorry just fixed

  3. dlukegordon commented on Jan 24, 2026

    @dlukegordon
    Author

    Confirmed fixed, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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