Skip to content

fix(nix): generate shell completions via Effect CLI flag - #51406

Closed
ReStranger wants to merge 1 commit into
anomalyco:v2from
ReStranger:nix-shell-completion
Closed

ReStranger wants to merge 1 commit into
anomalyco:v2from
ReStranger:nix-shell-completion

Conversation

@ReStranger

@ReStranger ReStranger commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Fixes #50408

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The nix package still called opencode completion, which disappeared with the Effect CLI migration — completion gets parsed as the root command's directory argument, so installPhase dies with ENOENT trying to chdir into it. I switched generation to opencode --completions <shell> (bash, zsh, fish), pipe the output through sed for the opencode2 alias since the scripts embed the command name, and made the cd packages/cli defensive because buildPhase leaves cwd there.

How did you verify your code works?

nix flake show and nix build --dry-run '.#opencode' pass

Screenshots / recordings

N/A — packaging change, no UI.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@ReStranger ReStranger closed this Sep 25, 2026
jerome-benoit added a commit to jerome-benoit/opencode that referenced this pull request Sep 28, 2026
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. `sh` is a
synonym for `bash`, so `--bash` already covers it; fish did not ship
before even though the CLI generates it.

Each shell is staged to a file before installation. A process substitution
does not propagate the generator's exit status, so a failure here would
install a zero-size completion and still pass — which is how the bug above
presented in the first place.

The command name is a build-time define, so `opencode2 --completions` just
reproduces the `opencode` scripts. They are renamed for the alias with
`substitute --replace-fail`, so a future change to the baked-in name breaks
the build instead of quietly shipping a second copy of the opencode one.

`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). The x86_64-darwin entry is dropped: nixpkgs' electron `tags` has
no such platform and `get` throws for it, so the value was never selected.

`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

Co-developed-by: @ReStranger (anomalyco#51406), @mindnbytes (anomalyco#50409)
jerome-benoit added a commit to jerome-benoit/opencode that referenced this pull request Sep 28, 2026
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. `sh` is a
synonym for `bash`, so `--bash` already covers it; fish did not ship
before even though the CLI generates it.

Each shell is staged to a file before installation. A process substitution
does not propagate the generator's exit status, so a failure here would
install a zero-size completion and still pass — which is how the bug above
presented in the first place.

The command name is a build-time define, so `opencode2 --completions` just
reproduces the `opencode` scripts. They are renamed for the alias with
`substitute --replace-fail`, so a future change to the baked-in name breaks
the build instead of quietly shipping a second copy of the opencode one.

`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). The x86_64-darwin entry is dropped: nixpkgs' electron `tags` has
no such platform and `get` throws for it, so the value was never selected.

`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

Co-developed-by: @ReStranger (anomalyco#51406), @mindnbytes (anomalyco#50409)
jerome-benoit added a commit to jerome-benoit/opencode that referenced this pull request Sep 28, 2026
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`, which
v2 removed: the Effect CLI parses it as the optional `directory` argument, so
the TUI opens instead and `installShellCompletion` gets a zero-size file. It
now uses the global `--completions <shell>` flag, stages each shell to a file
so a generator failure fails the build, and renames the `opencode2` copies
because the command name is a build-time define. Fish ships now; `sh` is a
synonym for `bash`.

`nix/electron.nix` 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. Refreshed from the 44.4.3 SHASUMS256.txt; the
headers hash recomputed the same way the 42.10.1 one was, reproducing it as
a control. The x86_64-darwin entry is dropped, nixpkgs' electron tags have
no such platform.

`nix/desktop.nix` stages the CLI executable but not the manifest that
`packages/desktop/scripts/utils.ts` reads the version from, so
`scripts/prebuild.ts` aborts on a missing package.json.

Fixes anomalyco#50408

Co-developed-by: @ReStranger (anomalyco#51406), @mindnbytes (anomalyco#50409)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant