Skip to content

Commit 88cb1aa

Browse files
committed
feat(opencode): switch from the default branch to the upstream v2 branch
OpenCode 2.x is the shipping line. The default branch still carries the 1.x `opencode2` binary; v2 inverts that, installing `opencode` and symlinking `opencode2` to it. The input now follows the root nixpkgs instead of pinning opencode's own. That drops an intermediate snapshot between releases and turns out to be what makes the build work: the node_modules FOD hash is only served from the binary cache for the derivation built from the root nixpkgs' bun, so the old arrangement had to build it locally and hit a hash mismatch. See the added note on #49063 for why that hash is not reproducible anyway. v2 changed the process model, and both consumers needed porting: - `oc()` used to scan for a free port and run `opencode --port`. v2 has no root-level `--port`; every client attaches to one background daemon, so the scan and the `OPENCODE_PORT` export are gone and the wrapper just runs the TUI in a per-project tmux session. - opencode.nvim likewise lost `opencode --port`. The plugin finds the daemon through the state directory instead, so the terminal command is plain `opencode`. It also stopped managing a per-invocation server process, which is all lsof and procps were there for; curl stays, the event stream is SSE. opencode-desktop moved to electron 44.x, which is no longer EOL, so the permittedInsecurePackages entry and the `electron_41` re-instancing that existed to keep the host nixpkgs config applied to it both go away. Blocked on anomalyco/opencode#51891, which fixes three defects that make the v2 packages unbuildable: completions are generated through a removed subcommand, nix/electron.nix carries hashes for electron 42.10.1 while the desktop pins 44.4.3, and the desktop never stages the CLI package manifest its prebuild reads. No local workarounds are carried for those. Refs anomalyco/opencode#50408
1 parent 79c9a88 commit 88cb1aa

7 files changed

Lines changed: 34 additions & 57 deletions

File tree

‎.serena/memories/modules_reference.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Shell configuration with oh-my-zsh:
141141
- Session variables: NH_FLAKE, WORKSPACE, EDITOR
142142
- Base plugins: colorize, screen, docker, python, poetry, rust, deno, volta, node, npm, etc.
143143
- Dynamic plugins based on: profile modules, distro, platform
144-
- Custom init: `oc()` tmux+opencode wrapper, EDITOR setup (code --wait), DVM support, .secrets loading with permission check
144+
- Custom init: `oc()` tmux wrapper around the opencode TUI (2.x runs one shared background daemon, so no per-project port is allocated), EDITOR setup (code --wait), DVM support, .secrets loading with permission check
145145
- envExtra: cargo env, gh auth token for NIX_CONFIG access-tokens and HOMEBREW_GITHUB_API_TOKEN
146146
- Profile: Volta setup, PATH configuration, .zprofile.d scripts sourcing
147147

@@ -208,7 +208,8 @@ Git TUI with dynamic theme colors from `themes.current`:
208208
OpenCode AI assistant:
209209

210210
- Options: `enable`, `enableDesktop`
211-
- Packages from flake input: TUI/CLI and Desktop variants
211+
- Packages from flake input: TUI/CLI and Desktop variants (`opencode2` is a symlink to the same v2 binary)
212+
- Desktop pins its own electron and builds against bare `nixpkgs.legacyPackages`, so the host nixpkgs insecure-package config does not apply to it
212213
- Warnings if packages unavailable for system
213214

214215
### bun.nix

‎.serena/memories/project_overview.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Home Manager configuration using Nix flakes for managing dotfiles and user envir
1818
| ------------------------- | ------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------- |
1919
| `nixpkgs` | `github:nixos/nixpkgs?ref=nixpkgs-unstable` | Nix packages (unstable) |
2020
| `home-manager` | `github:nix-community/home-manager` | Home Manager, follows nixpkgs |
21-
| `opencode` | `github:anomalyco/opencode` | OpenCode TUI/CLI/Desktop |
21+
| `opencode` | `github:anomalyco/opencode/v2` | OpenCode 2.x TUI/CLI/Desktop (v2 branch, follows nixpkgs) |
2222
| `opencode-nvim` | `github:NickvanDyke/opencode.nvim` | Neovim plugin (non-flake) |
2323
| `agent-of-empires` | `github:agent-of-empires/agent-of-empires` | AI agent session manager (non-flake) |
2424
| `herdr` | `github:ogulcancelik/herdr` | Terminal multiplexer for AI coding agents (flake, follows nixpkgs; bundles rust-overlay) |

‎flake.lock‎

Lines changed: 7 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎flake.nix‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@
1111
url = "github:Mic92/sops-nix";
1212
inputs.nixpkgs.follows = "nixpkgs";
1313
};
14-
# Workaround: opencode calibrates its node_modules FOD hash against the
15-
# bun of its own nixpkgs.
16-
# Remove when upstream makes hashes.json bun-agnostic (opencode#49063).
17-
opencode.url = "github:anomalyco/opencode";
14+
# opencode builds against its own nixpkgs unless told otherwise, which
15+
# pins an intermediate snapshot between releases. Follow the root nixpkgs
16+
# so both track the same commit; opencode's node_modules hash is calibrated
17+
# against whatever bun that nixpkgs ships, so the two must move together.
18+
# Pinned to the v2 branch: OpenCode 2.x is the shipping line.
19+
opencode = {
20+
url = "github:anomalyco/opencode/v2";
21+
inputs.nixpkgs.follows = "nixpkgs";
22+
};
1823
opencode-nvim = {
1924
url = "github:NickvanDyke/opencode.nvim";
2025
flake = false;
@@ -170,10 +175,7 @@
170175
nvidia.acceptLicense = true;
171176
# Workaround: Darwin Nheko resolves to insecure olm-3.2.16.
172177
# Remove when that dependency leaves Nheko's closure or is no longer insecure.
173-
# Workaround: opencode-desktop pins EOL electron_41.
174-
permittedInsecurePackages = nixpkgs.lib.optionals isDarwin [ "olm-3.2.16" ] ++ [
175-
"electron-41.10.6"
176-
];
178+
permittedInsecurePackages = nixpkgs.lib.optionals isDarwin [ "olm-3.2.16" ];
177179
};
178180
};
179181

‎home-manager/modules/development/opencode.nix‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,9 @@ let
3131
desktop = inputs.opencode.packages.${system}.opencode-desktop or null;
3232
in
3333
if desktop != null then
34-
desktop.override {
35-
opencode = opencodePackage;
36-
# opencode builds with bare nixpkgs.legacyPackages: re-instance the
37-
# EOL electron_41 pin here so permittedInsecurePackages applies.
38-
electron_41 = pkgs.electron_41;
39-
}
34+
# opencode-desktop builds with bare nixpkgs.legacyPackages and pins its own
35+
# electron, so the host nixpkgs config does not reach it.
36+
desktop.override { opencode = opencodePackage; }
4037
else
4138
null;
4239

‎home-manager/modules/editors/neovim.nix‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,9 @@ let
361361

362362
nvimOpencodeConfig = lib.optionalString cfg.plugins.opencode.enable ''
363363
-- OpenCode AI Integration
364-
local opencode_cmd = "opencode --port"
364+
-- OpenCode 2.x runs a single background daemon; launching the TUI registers
365+
-- it and the plugin discovers the service through the state directory.
366+
local opencode_cmd = "opencode"
365367
local opencode_terminal_opts = {
366368
win = {
367369
position = "right",
@@ -543,11 +545,9 @@ in
543545
pkgs.tree-sitter
544546
]
545547
++ lib.optionals cfg.plugins.opencode.enable (
546-
[
547-
pkgs.curl
548-
pkgs.lsof
549-
(if pkgs.stdenv.hostPlatform.isDarwin then pkgs.uutils-procps else pkgs.procps)
550-
]
548+
# The plugin streams events over SSE with curl; it no longer manages a
549+
# per-invocation server process, so lsof/procps are gone in v2.
550+
[ pkgs.curl ]
551551
++ lib.optional (
552552
config.modules.development.opencode.opencodePackage != null
553553
) config.modules.development.opencode.opencodePackage

‎home-manager/modules/shell/zsh.nix‎

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,13 @@ in
126126
local path_hash=$(echo "$PWD" | shasum | cut -c1-4)
127127
local session_name="''${base_name}-''${path_hash}"
128128
129-
# Find available port starting from 4096
130-
local port=4096
131-
while [ $port -lt 5096 ]; do
132-
if ! lsof -i :$port >/dev/null 2>&1; then
133-
break
134-
fi
135-
port=$((port + 1))
136-
done
137-
138-
export OPENCODE_PORT=$port
139-
129+
# OpenCode 2.x runs a single background daemon that every client
130+
# attaches to, so only the TUI is scoped to this project.
140131
if [ -n "$TMUX" ]; then
141-
# Already inside tmux - just run with port
142-
opencode --port $port "$@"
132+
opencode "$@"
143133
else
144134
# Create tmux session and run opencode
145-
local oc_cmd="OPENCODE_PORT=$port opencode --port $port $*; exec $SHELL"
135+
local oc_cmd="opencode $*; exec $SHELL"
146136
if tmux has-session -t "$session_name" 2>/dev/null; then
147137
tmux new-window -t "$session_name" -c "$PWD" "$oc_cmd"
148138
tmux attach-session -t "$session_name"

0 commit comments

Comments
 (0)