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

Closed
opened 2026-02-16 18:07:17 -05:00 by yindo · 3 comments
Owner

Originally created by @dlukegordon on GitHub (Jan 24, 2026).

Originally assigned to: @thdxr on GitHub.

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

Originally created by @dlukegordon on GitHub (Jan 24, 2026). Originally assigned to: @thdxr on GitHub. ## 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](https://github.com/anomalyco/opencode/pull/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"; ``` 2. Add opencode package: ``` environment.systemPackages = with pkgs; [ inputs.opencode.packages.${pkgs.stdenv.hostPlatform.system}.default ]; ``` 3. Run `nixos-switch` ``` sudo nixos-rebuild switch ``` ### Screenshot and/or share link _No response_ ### Operating System NixOS 25.11 ### Terminal Ghostty
yindo added the bugnix labels 2026-02-16 18:07:17 -05:00
yindo closed this issue 2026-02-16 18:07:17 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 24, 2026):

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

  • #9758: The MODELS_DEV_API_JSON environment variable has been configured but is ineffective.

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

@github-actions[bot] commented on GitHub (Jan 24, 2026): This issue might be a duplicate of existing issues. Please check: - #9758: The MODELS_DEV_API_JSON environment variable has been configured but is ineffective. Feel free to ignore if none of these address your specific case.
Author
Owner

@thdxr commented on GitHub (Jan 24, 2026):

sorry just fixed

@thdxr commented on GitHub (Jan 24, 2026): sorry just fixed
Author
Owner

@dlukegordon commented on GitHub (Jan 24, 2026):

Confirmed fixed, thanks!

@dlukegordon commented on GitHub (Jan 24, 2026): Confirmed fixed, thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7472