Skip to content

feat(nix): install shell completions - #961

Merged
nklmilojevic merged 1 commit into
mainfrom
feat/shell-completions
Oct 22, 2026
Merged

nklmilojevic merged 1 commit into
mainfrom
feat/shell-completions

Conversation

@nklmilojevic

Copy link
Copy Markdown
Owner

The Nix package shipped only bin/, so shells never got sofka's completions.

  • postInstall runs sofka completion bash|fish|zsh and installs the output with installShellCompletion. It is skipped when cross-compiling.
  • installShellFiles goes on the final package only. commonArgs is unchanged, so the cached dependency build stays the same.

Checked: nix build .#sofka produces share/{bash-completion,fish/vendor_completions.d,zsh/site-functions}. The fish script parses with fish -n.

@kritikal-github

kritikal-github Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Re-runViewConfidence Score: 5/5

[Medium risk] The risk is medium because the post-install hook changes the Nix package build and installed shell behavior, but a revert would undo it without persistent effects.

Findings

Summary

Installs Bash, Fish, and Zsh completions in the Nix package

The final derivation in package.nix runs the installed sofka binary during postInstall and passes its generated scripts to nixpkgs' installShellCompletion hook. The hook places them under the shell-specific share directories, while the build-platform guard leaves cross-built packages without generated scripts. The existing flake.nix package and check outputs use that derivation, so their native builds will include the completion files.

Flow
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["Nix builds sofka binary"] --> B{"Build platform can run binary?"}
  B -->|yes| C["Generate Bash, Fish, and Zsh registrations"]
  C --> D["Install scripts in shell share directories"]
  B -->|no| E["Keep package without generated completions"]
  D --> F["Native Nix package"]
  E --> G["Cross-built Nix package"]
Loading

What's good

  • Keeps installShellFiles out of commonArgs, preserving the dependency derivation's inputs.
  • Guards execution of the newly built binary when cross-compiling.
Review context · 3 sources · 2/6 commands

Reviews (1) · Last reviewed commit: "feat(nix): install shell completions" · gpt-6-sol

Comment thread package.nix
# Kept out of commonArgs so the cached dependency build is unchanged.
nativeBuildInputs = commonArgs.nativeBuildInputs ++ [ installShellFiles ];

postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Update shell setup guidance for Nix installs · maintainability

For native Nix installs, the new postInstall supplies completion scripts in the package's standard shell directories, but docs/shell-completion.md still tells every user to generate and source them at shell startup and says they must generate them again after an update. Nix users following those instructions load an additional registration even when their shell loads the installed scripts automatically. Distinguish the Nix package's installed completions from the manual setup instructions, including the cross-compiled case where this guard skips installation.

Suggested fix

Update docs/shell-completion.md to say native Nix package builds install Bash/Fish/Zsh completion files automatically where the shell's completion search path includes the package's share directory; keep manual generation instructions for other installations and cross-built Nix packages.

Prompt for a coding agent
In docs/shell-completion.md, amend the shell setup section so it documents the Bash/Fish/Zsh completion files now shipped by native Nix builds, when manual sourcing remains necessary, and that package.nix skips generating these files when cross-compiling.

Comment thread package.nix
Comment on lines +40 to +43
installShellCompletion --cmd sofka \
--bash <($out/bin/sofka completion bash) \
--fish <($out/bin/sofka completion fish) \
--zsh <($out/bin/sofka completion zsh)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Assert completion files in the Nix package check · tests

When nix flake check builds the sofka package through flake.nix, it checks only that the derivation succeeds. It does not check that postInstall populated all three expected completion paths with usable output, so removing one shell argument or incorrectly naming a file would still pass. Add a native package check that asserts each installed file exists and is nonempty (and, if available, parses the Fish script).

Suggested fix

Add a check under flake.nix checks that depends on pkgs.sofka and asserts nonempty share/bash-completion/completions/sofka.bash, share/fish/vendor_completions.d/sofka.fish, and share/zsh/site-functions/_sofka; run fish -n on the installed Fish script if fish is provided as a native build input for the check.

Prompt for a coding agent
Add a native Nix check in flake.nix that depends on the packaged sofka output and verifies all three installed shell-completion filenames are present and nonempty, with an optional fish -n check. Keep it separate from commonArgs so the cached dependency build remains unchanged.

@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Summary

Installs bash, fish, and zsh completions in the Nix package.

  • Nix packages now include bash, fish, and zsh completions.

Reviews (1) · Last reviewed commit: "feat(nix): install shell completions" · Reviewed by Greptile

@nklmilojevic
nklmilojevic merged commit 42d35c0 into main Oct 22, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant