From 7c674db9b692ad353afd962e64bb5dc899fceb95 Mon Sep 17 00:00:00 2001 From: ReStranger Date: Sat, 18 Jul 2026 19:40:28 +0300 Subject: [PATCH 1/3] feat(nix): build opencode2 (TUI) alongside opencode - Build packages/cli (opencode2 TUI binary) in the same derivation - Install opencode2 to /bin alongside opencode - Add wrapProgram for opencode2 with ripgrep in PATH --- flake.nix | 2 +- nix/desktop.nix | 4 ++-- nix/opencode.nix | 27 ++++++++++++++++++--------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/flake.nix b/flake.nix index 8737c3b542f7..579fb17cfef9 100644 --- a/flake.nix +++ b/flake.nix @@ -22,7 +22,7 @@ default = pkgs.mkShell { packages = with pkgs; [ bun - nodejs_20 + nodejs_26 pkg-config openssl git diff --git a/nix/desktop.nix b/nix/desktop.nix index d0d7fa7eca1f..552ca88168a1 100644 --- a/nix/desktop.nix +++ b/nix/desktop.nix @@ -2,7 +2,7 @@ lib, stdenv, bun, - nodejs, + nodejs_26, darwin, electron_41, makeWrapper, @@ -24,7 +24,7 @@ stdenv.mkDerivation (finalAttrs: { nativeBuildInputs = [ bun - nodejs + nodejs_26 makeWrapper writableTmpDirAsHomeHook ] ++ lib.optionals stdenv.hostPlatform.isLinux [ diff --git a/nix/opencode.nix b/nix/opencode.nix index a22f7d3d2473..a632b46ce70d 100644 --- a/nix/opencode.nix +++ b/nix/opencode.nix @@ -3,7 +3,7 @@ stdenvNoCC, callPackage, bun, - nodejs, + nodejs_26, sysctl, makeBinaryWrapper, models-dev, @@ -20,7 +20,7 @@ stdenvNoCC.mkDerivation (finalAttrs: { nativeBuildInputs = [ bun - nodejs # for patchShebangs node_modules + nodejs_26 # for patchShebangs node_modules installShellFiles makeBinaryWrapper models-dev @@ -32,6 +32,11 @@ stdenvNoCC.mkDerivation (finalAttrs: { substituteInPlace packages/script/src/index.ts \ --replace-fail 'throw new Error(`This script requires bun@''${expectedBunVersionRange}' \ 'console.warn(`Warning: This script requires bun@''${expectedBunVersionRange}' + + # Nix builds are network-restricted. Reuse the provided Node binary for SEA packaging + # instead of trying to download the exact upstream Node version at build time. + substituteInPlace packages/cli/script/build-node.ts \ + --replace-fail ' if (info.version === NODE_VERSION) return realpath(info.path)' ' return realpath(info.path)' ''; configurePhase = '' @@ -48,13 +53,14 @@ stdenvNoCC.mkDerivation (finalAttrs: { env.OPENCODE_DISABLE_MODELS_FETCH = true; env.OPENCODE_VERSION = finalAttrs.version; env.OPENCODE_CHANNEL = "prod"; + env.NODE_BIN = "${nodejs_26}/bin/node"; buildPhase = '' runHook preBuild + cd packages/cli + bun --bun ./script/build-node.ts --single --skip-install - cd ./packages/opencode - bun --bun ./script/build.ts --single --skip-install - bun --bun ./script/schema.ts schema.json + cd ../opencode runHook postBuild ''; @@ -62,8 +68,7 @@ stdenvNoCC.mkDerivation (finalAttrs: { installPhase = '' runHook preInstall - install -Dm755 dist/opencode-*/bin/opencode $out/bin/opencode - install -Dm644 schema.json $out/share/opencode/schema.json + install -Dm755 dist/cli-node-*/bin/opencode2-node $out/bin/opencode wrapProgram $out/bin/opencode \ --prefix PATH : ${ @@ -76,6 +81,8 @@ stdenvNoCC.mkDerivation (finalAttrs: { ) } + ln -s opencode $out/bin/opencode2 + runHook postInstall ''; @@ -91,11 +98,13 @@ stdenvNoCC.mkDerivation (finalAttrs: { writableTmpDirAsHomeHook ]; doInstallCheck = true; - versionCheckKeepEnvironment = [ "HOME" "OPENCODE_DISABLE_MODELS_FETCH" ]; + versionCheckKeepEnvironment = [ + "HOME" + "OPENCODE_DISABLE_MODELS_FETCH" + ]; versionCheckProgramArg = "--version"; passthru = { - jsonschema = "${placeholder "out"}/share/opencode/schema.json"; env = finalAttrs.env; }; From e4aabb89a499b71050409da6491a203d7b837402 Mon Sep 17 00:00:00 2001 From: ReStranger Date: Mon, 20 Jul 2026 17:14:40 +0300 Subject: [PATCH 2/3] chore(nix): update flake inputs to get nodejs_26 Signed-off-by: ReStranger --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 1c8e62bd825d..6845a887fca8 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1776683584, - "narHash": "sha256-NuTLMrr10Tng72hurYG8jYQ4XKK8wnpJmOGcPiis96g=", + "lastModified": 1784525419, + "narHash": "sha256-yocJ4I4Kd4as0UPMFs9P7laPvvA2x/Bj8EW46iW3VVM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9dd5558b06dbdacbf635a3dd36dce1b1a7ee3a89", + "rev": "a16c3fde2ffeab7f6326f50f460aaffde7ae066d", "type": "github" }, "original": { From 727c204fc2b0b9bed0ce1a3ddfc1586f281a65fa Mon Sep 17 00:00:00 2001 From: ReStranger Date: Tue, 21 Jul 2026 06:22:15 +0300 Subject: [PATCH 3/3] fix(nix): get package version via self Signed-off-by: ReStranger --- flake.nix | 4 ++++ nix/node_modules.nix | 9 +++------ nix/opencode.nix | 2 -- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/flake.nix b/flake.nix index 579fb17cfef9..f5ca3b75825e 100644 --- a/flake.nix +++ b/flake.nix @@ -36,6 +36,7 @@ let node_modules = final.callPackage ./nix/node_modules.nix { inherit rev; + version = self.opencodeVersion; }; in rec { @@ -53,6 +54,7 @@ let node_modules = pkgs.callPackage ./nix/node_modules.nix { inherit rev; + version = self.opencodeVersion; }; in rec { @@ -69,5 +71,7 @@ }; } ); + + opencodeVersion = (builtins.fromJSON (builtins.readFile ./package.json)).version; }; } diff --git a/nix/node_modules.nix b/nix/node_modules.nix index e10e85d2fe41..618400328750 100644 --- a/nix/node_modules.nix +++ b/nix/node_modules.nix @@ -2,6 +2,7 @@ lib, stdenvNoCC, bun, + version, rev ? "dirty", hash ? (lib.pipe ./hashes.json [ @@ -10,17 +11,13 @@ ]).nodeModules.${stdenvNoCC.hostPlatform.system}, }: let - packageJson = lib.pipe ../packages/opencode/package.json [ - builtins.readFile - builtins.fromJSON - ]; platform = stdenvNoCC.hostPlatform; bunCpu = if platform.isAarch64 then "arm64" else "x64"; bunOs = if platform.isLinux then "linux" else "darwin"; in stdenvNoCC.mkDerivation { pname = "opencode-node_modules"; - version = "${packageJson.version}+${lib.replaceString "-" "." rev}"; + version = "${version}+${lib.replaceString "-" "." rev}"; src = lib.fileset.toSource { root = ../.; @@ -52,7 +49,7 @@ stdenvNoCC.mkDerivation { --cpu="${bunCpu}" \ --os="${bunOs}" \ --filter '!./' \ - --filter './packages/opencode' \ + --filter './packages/cli' \ --filter './packages/desktop' \ --filter './packages/app' \ --frozen-lockfile \ diff --git a/nix/opencode.nix b/nix/opencode.nix index a632b46ce70d..a52619e521a0 100644 --- a/nix/opencode.nix +++ b/nix/opencode.nix @@ -60,8 +60,6 @@ stdenvNoCC.mkDerivation (finalAttrs: { cd packages/cli bun --bun ./script/build-node.ts --single --skip-install - cd ../opencode - runHook postBuild '';