Skip to content

Commit eae7ee7

Browse files
committed
fix(nix): make the v2 packages buildable
Three independent defects in the v2 Nix packaging, each fatal to `nix build .#opencode` or `nix build .#opencode-desktop`. `nix/opencode.nix` generates completions through `opencode completion`, a subcommand v2 no longer has. The Effect CLI parses it as the optional `directory` argument and the TUI opens instead, so `installShellCompletion` gets a zero-size file and the build fails: Error: ENOENT: no such file or directory, chdir '/build/source/packages/cli' -> 'completion' ERROR: installShellCompletion: installed shell completion file .../opencode.bash does not exist or has zero size Completions now come from the Effect-CLI global action flag, `--completions <bash|zsh|fish|sh>`. Naming the shell directly also drops the `SHELL=/bin/zsh` coaxing the old yargs-based path needed. The name in the output is a build-time define, so `opencode2 --completions` just reproduces the `opencode` script; it is renamed instead. `sh` is a synonym for `bash` in the Effect CLI, so `--bash` already covers it. Fish did not ship before, but the CLI generates it and `installShellFiles` knows where to put it, so it is installed now. `nix/electron.nix` still carries the electron 42.10.1 hashes while `packages/desktop/package.json` moved to 44.4.3, so the desktop's electron fetchzip cannot resolve. The hashes are refreshed from the 44.4.3 SHASUMS256.txt; the headers hash is the fetchzip recursive hash, computed the same way the 42.10.1 one was (reproducing the previous value as a control). `nix/desktop.nix` stages the CLI executable but not the package manifest next to it, and `packages/desktop/scripts/utils.ts` reads the bundled CLI's version from that manifest. The desktop build aborts in `scripts/prebuild.ts`: ENOENT: no such file or directory, open '/build/desktop-cli/cli-linux-x64-baseline/package.json' The manifest is now written alongside the executable, so the version file the desktop ships resolves without spawning the binary. Fixes anomalyco#50408
1 parent dd786c6 commit eae7ee7

3 files changed

Lines changed: 21 additions & 11 deletions

File tree

‎nix/desktop.nix‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ stdenv.mkDerivation (finalAttrs: {
9191
cli_package=$(bun -e 'import { getCurrentCli } from "./scripts/utils.ts"; console.log(getCurrentCli().package.replace("@opencode/", ""))')
9292
mkdir -p "$OPENCODE_CLI_DIST/$cli_package/bin"
9393
cp ${lib.getExe opencode} "$OPENCODE_CLI_DIST/$cli_package/bin/opencode"
94+
# scripts/utils.ts reads the CLI version from the package manifest that sits
95+
# next to the executable, so stage one beside it.
96+
printf '{"name":"@opencode/%s","version":"%s"}\n' "$cli_package" "$version" \
97+
> "$OPENCODE_CLI_DIST/$cli_package/package.json"
9498
9599
bun run build
96100
npx electron-builder --dir \

‎nix/electron.nix‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ let
33
version = (builtins.fromJSON (builtins.readFile ../packages/desktop/package.json)).devDependencies.electron;
44
in
55
(callPackage (path + "/pkgs/development/tools/electron/binary/generic.nix") { }) version {
6-
# Electron 42.10.1 SHASUMS256.txt; update with the desktop package version.
7-
aarch64-linux = "20e68d6c4e47f3ebf59de7c6b1f8b8bec6a6ebda6a451132f9b465f3f13ce467";
8-
x86_64-linux = "2452b27112d92387471fa2488aafac85d79ea3f2ee1216c0abd5150d6c12362b";
9-
aarch64-darwin = "ac7194a3dfd81930ba35355c01620262c1254752859b42dcb8f4b9e4d174a871";
10-
x86_64-darwin = "4489aba55477a0082266cb690db1c829503ba3338048599d8fd243953df37dab";
6+
# Electron 44.4.3 SHASUMS256.txt; update with the desktop package version.
7+
aarch64-linux = "61f084a5ac0f1835efc12b9db17042d92c8c617b03578f96a888acd4a05a0b10";
8+
x86_64-linux = "fe880a7e37160cfd4e00193bc4c713ead7a778abfe74860a2d36d86fd0be48a8";
9+
aarch64-darwin = "6b728f5dcfae74f3f936f2bca5b3cd9b9659ffea464f67939f004acb55425a85";
10+
x86_64-darwin = "015b52631d92187b552ff4e047255f596a7af4707e388a5890951f0b2645764e";
1111
# fetchzip hashes the unpacked headers, not the release tarball.
12-
headers = "sha256-4eUy3BZVvxTl7KUOsxio7769lL6ag/ecbeK+qLURWMI=";
12+
headers = "sha256-QPkX+99kArlQhhbgOZe+Hsk28G5cadkUy0G0cIDtEh8=";
1313
}

‎nix/opencode.nix‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,20 @@ stdenvNoCC.mkDerivation (finalAttrs: {
8585
'';
8686

8787
postInstall = lib.optionalString (stdenvNoCC.buildPlatform.canExecute stdenvNoCC.hostPlatform) ''
88-
# trick yargs into also generating zsh completions
88+
# Effect-CLI exposes completions as a global action flag, so each shell is
89+
# named directly instead of being coaxed out of the argument parser.
90+
# 'sh' is a synonym for 'bash', so it adds nothing over --bash.
8991
installShellCompletion --cmd opencode \
90-
--bash <($out/bin/opencode completion) \
91-
--zsh <(SHELL=/bin/zsh $out/bin/opencode completion)
92+
--bash <($out/bin/opencode --completions bash) \
93+
--fish <($out/bin/opencode --completions fish) \
94+
--zsh <($out/bin/opencode --completions zsh)
9295
96+
# The command name is a build-time define, so opencode2 --completions only
97+
# repeats the script above verbatim. Rename it instead.
9398
installShellCompletion --cmd opencode2 \
94-
--bash <($out/bin/opencode2 completion) \
95-
--zsh <(SHELL=/bin/zsh $out/bin/opencode2 completion)
99+
--bash <($out/bin/opencode --completions bash | sed 's/opencode/opencode2/g') \
100+
--fish <($out/bin/opencode --completions fish | sed 's/opencode/opencode2/g') \
101+
--zsh <($out/bin/opencode --completions zsh | sed 's/opencode/opencode2/g')
96102
'';
97103

98104
nativeInstallCheckInputs = [

0 commit comments

Comments
 (0)