Nix build fails when shell completion generation produces empty output #6722

Closed
opened 2026-02-16 18:05:03 -05:00 by yindo · 4 comments
Owner

Originally created by @jerome-benoit on GitHub (Jan 18, 2026).

Originally assigned to: @thdxr on GitHub.

Problem

The Nix build fails with the following error:

ERROR: installShellCompletion: installed shell completion file does not exist or has zero size

This occurs when:

  • The opencode completion command fails or returns empty output during the build
  • bash or zsh shells are not installed in the build environment

Expected Behavior

The Nix build should succeed even if shell completions cannot be generated. Shell completions are optional and their absence should not prevent the package from being built.

Proposed Solution

Make the shell completion installation resilient to failures by:

  1. Capturing completion output before installation
  2. Adding error handling with `|| true`
  3. Only installing completions if they contain actual content
  4. Using safe piping to avoid empty file errors
Originally created by @jerome-benoit on GitHub (Jan 18, 2026). Originally assigned to: @thdxr on GitHub. ## Problem The Nix build fails with the following error: ``` ERROR: installShellCompletion: installed shell completion file does not exist or has zero size ``` This occurs when: - The `opencode completion` command fails or returns empty output during the build - bash or zsh shells are not installed in the build environment ## Expected Behavior The Nix build should succeed even if shell completions cannot be generated. Shell completions are optional and their absence should not prevent the package from being built. ## Proposed Solution Make the shell completion installation resilient to failures by: 1. Capturing completion output before installation 2. Adding error handling with \`|| true\` 3. Only installing completions if they contain actual content 4. Using safe piping to avoid empty file errors
yindo added the nix label 2026-02-16 18:05:03 -05:00
yindo closed this issue 2026-02-16 18:05:03 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 18, 2026):

This issue might be a duplicate of or related to existing issues. Please check:

  • #8962: Desktop build on nixos - Direct Nix build failure with IPC requests
  • #5914: NixOS: custom tools fail because they cannot find imported modules - Module resolution issues in Nix builds
  • #4853: When built from the flake, opencode package is extremely large (4GB+) - Nix flake configuration issues
  • #6750: Intermittent empty output from Bash/Tool execution - Similar empty output problem
  • #7207: opencode shell output empty - Related shell command output issues
  • #7540: Does not build on Arch Linux - Related build environment failures
  • #8188: [build from src] 'bun install' Failed in Docker - Similar environment-specific build issues
  • #9273: Binary name collision blocks Nix packaging - Related Nix packaging blocker

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 18, 2026): This issue might be a duplicate of or related to existing issues. Please check: - #8962: Desktop build on nixos - Direct Nix build failure with IPC requests - #5914: NixOS: custom tools fail because they cannot find imported modules - Module resolution issues in Nix builds - #4853: When built from the flake, opencode package is extremely large (4GB+) - Nix flake configuration issues - #6750: Intermittent empty output from Bash/Tool execution - Similar empty output problem - #7207: opencode shell output empty - Related shell command output issues - #7540: Does not build on Arch Linux - Related build environment failures - #8188: [build from src] 'bun install' Failed in Docker - Similar environment-specific build issues - #9273: Binary name collision blocks Nix packaging - Related Nix packaging blocker Feel free to ignore if none of these address your specific case.
Author
Owner

@ndrwstn commented on GitHub (Jan 21, 2026):

Affected User Report

I'm experiencing this exact issue on my Darwin (macOS) system after the recent nix flake overhaul in PR #9032.

Build Environment

  • System: aarch64-darwin (macOS)
  • Commit: 09d2fd57ff7aaaff714e23cb89859611d0a95f9e
  • Version: 1.1.30-09d2fd5
  • Build tool: darwin-rebuild (via nh)

Error Output

ERROR: installShellCompletion: installed shell completion file 
`/nix/store/b7y09kp0hx1szl4n9piczbdhwclp9r27-opencode-1.1.30-09d2fd5/share/bash-completion/completions/opencode.bash` 
does not exist or has zero size

Observations

  • The build phase completes successfully ("building opencode-darwin-arm64", "schema.json" generated)
  • Only the installPhase fails when trying to install shell completions
  • This appears to have been introduced in the recent nix flake overhaul (PR #9032 merged Jan 18)

Impact

This is currently blocking Darwin users from building/updating opencode via Nix flakes.

@gigamonster256 Since this appears related to PR #9032, would you be able to take a look? The proposed solutions in the issue description (making completion installation resilient to failures) seem reasonable.

@ndrwstn commented on GitHub (Jan 21, 2026): ## Affected User Report I'm experiencing this exact issue on my Darwin (macOS) system after the recent nix flake overhaul in PR #9032. ### Build Environment - **System**: `aarch64-darwin` (macOS) - **Commit**: `09d2fd57ff7aaaff714e23cb89859611d0a95f9e` - **Version**: `1.1.30-09d2fd5` - **Build tool**: `darwin-rebuild` (via `nh`) ### Error Output ``` ERROR: installShellCompletion: installed shell completion file `/nix/store/b7y09kp0hx1szl4n9piczbdhwclp9r27-opencode-1.1.30-09d2fd5/share/bash-completion/completions/opencode.bash` does not exist or has zero size ``` ### Observations - The build phase completes successfully ("building opencode-darwin-arm64", "schema.json" generated) - Only the `installPhase` fails when trying to install shell completions - This appears to have been introduced in the recent nix flake overhaul (PR #9032 merged Jan 18) ### Impact This is currently blocking Darwin users from building/updating opencode via Nix flakes. @gigamonster256 Since this appears related to PR #9032, would you be able to take a look? The proposed solutions in the issue description (making completion installation resilient to failures) seem reasonable.
Author
Owner

@jerome-benoit commented on GitHub (Jan 21, 2026):

It's because the nixpkgs hash in the repo reference a snapshot with issues on darwin, make your opencode integration follow the current:

    opencode.url = "github:anomalyco/opencode";
    opencode.inputs.nixpkgs.follows = "nixpkgs";
@jerome-benoit commented on GitHub (Jan 21, 2026): It's because the nixpkgs hash in the repo reference a snapshot with issues on darwin, make your opencode integration follow the current: ```nix opencode.url = "github:anomalyco/opencode"; opencode.inputs.nixpkgs.follows = "nixpkgs"; ```
Author
Owner

@gigamonster256 commented on GitHub (Jan 21, 2026):

this is exceedingly strange, opencode is building successfully in CI - leading me to believe some env vars are leaking into the nix build environment on local (possibly unsandboxed?) builds which cause yargs to generate zsh completions 2 times instead of 1 time for bash and 1 time for zsh

edit: i just pulled out my M1 macbook and get the same issue, let me experiment a bit with the build to see if I can get completions working/if my theory is correct

edit: hmm, it looks like the opencode binary is crashing with a 255 return code - possibly a bug with bun or similar since @jerome-benoit says using a different nixpkgs checkout fixes it - must be a cpu feature specific bug since the CI machine builds/tests just fine

@gigamonster256 commented on GitHub (Jan 21, 2026): this is exceedingly strange, opencode is building successfully in CI - leading me to believe some env vars are leaking into the nix build environment on local (possibly unsandboxed?) builds which cause yargs to generate zsh completions 2 times instead of 1 time for bash and 1 time for zsh edit: i just pulled out my M1 macbook and get the same issue, let me experiment a bit with the build to see if I can get completions working/if my theory is correct edit: hmm, it looks like the opencode binary is crashing with a 255 return code - possibly a bug with bun or similar since @jerome-benoit says using a different nixpkgs checkout fixes it - must be a cpu feature specific bug since the CI machine builds/tests just fine
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#6722