[PR #3924] feat: nix support for the nix folks #10805

Closed
opened 2026-02-16 18:15:33 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/3924

State: closed
Merged: Yes


Adds Nix flake (+ supporting CI tools) to build OpenCode from source.

To enable this, a few tweaks were done to the core TS codebase that shouldn't impact non-nix builds/runtimes:

  • packages/opencode/src/cli/cmd/tui/thread.ts
    • Nix builds produce a standalone binary with a pre-bundled worker (opencode-worker.js) next to the executable. The new logic checks for this bundled worker and prefers it over the development-time worker.ts URL.
    • Wrap worker instantiation in try-catch to handle worker init failures. If the worker fails (e.g., missing worker bundle), falls back to an inline server instance; the binary should work even if the worker bundle is missing/incompatible with the platform.
  • packages/opencode/src/provider/models-macro.ts
    • Checks for MODELS_DEV_API_JSON env var pointing to a pre-fetched copy of the models API JSON. During Nix builds, process the pre-fetched json and inject its path via this env var. Allows builds to complete without network calls.
  • packages/sdk/js/src/gen/client/utils.gen.ts
    • Adds string coercion for config.baseUrl to handles cases where baseUrl might be a URL object or other non-string type during Nix builds, where bundling/compilation may preserve different object types.
  • packages/opencode/src/tool/bash.ts
    • Previously used relative URLs in compiled bundles causing the runtime not being able to resolve wasm assets if they were packaged differently. We now resolve those URLs to absolute paths regardless of packaging method.

GitHub workflow CI:

  • update-nix-hashes.yml triggers whenever updates to package/lock files are pushed/merged.
  • The job forces a rebuild of the node_modules FOD to get the new hash, and commits the result to hashes.json

relates to:
#3540
#3739
#462
#1903

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/3924 **State:** closed **Merged:** Yes --- Adds Nix flake (+ supporting CI tools) to build OpenCode from source. To enable this, a few tweaks were done to the core TS codebase that shouldn't impact non-nix builds/runtimes: - `packages/opencode/src/cli/cmd/tui/thread.ts` - Nix builds produce a standalone binary with a pre-bundled worker (`opencode-worker.js`) next to the executable. The new logic checks for this bundled worker and prefers it over the development-time `worker.ts` URL. - Wrap worker instantiation in try-catch to handle worker init failures. If the worker fails (e.g., missing worker bundle), falls back to an inline server instance; the binary should work even if the worker bundle is missing/incompatible with the platform. - `packages/opencode/src/provider/models-macro.ts` - Checks for `MODELS_DEV_API_JSON` env var pointing to a pre-fetched copy of the models API JSON. During Nix builds, process the pre-fetched json and inject its path via this env var. Allows builds to complete without network calls. - `packages/sdk/js/src/gen/client/utils.gen.ts` - Adds string coercion for `config.baseUrl` to handles cases where `baseUrl` might be a URL object or other non-string type during Nix builds, where bundling/compilation may preserve different object types. - `packages/opencode/src/tool/bash.ts` - Previously used relative URLs in compiled bundles causing the runtime not being able to resolve wasm assets if they were packaged differently. We now resolve those URLs to absolute paths regardless of packaging method. GitHub workflow CI: - `update-nix-hashes.yml` triggers whenever updates to package/lock files are pushed/merged. - The job forces a rebuild of the node_modules FOD to get the new hash, and commits the result to `hashes.json` --- relates to: #3540 #3739 #462 #1903
yindo added the pull-request label 2026-02-16 18:15:33 -05:00
yindo closed this issue 2026-02-16 18:15:33 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10805