Repository navigation
feat(nix): install shell completions - #961
Conversation
[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
SummaryInstalls 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"]
What's good
Review context · 3 sources · 2/6 commandsReviews (1) · Last reviewed commit: "feat(nix): install shell completions" · gpt-6-sol |
| # Kept out of commonArgs so the cached dependency build is unchanged. | ||
| nativeBuildInputs = commonArgs.nativeBuildInputs ++ [ installShellFiles ]; | ||
|
|
||
| postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) '' |
There was a problem hiding this comment.
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.
| installShellCompletion --cmd sofka \ | ||
| --bash <($out/bin/sofka completion bash) \ | ||
| --fish <($out/bin/sofka completion fish) \ | ||
| --zsh <($out/bin/sofka completion zsh) |
There was a problem hiding this comment.
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.
[Low impact] The PR appears safe to merge. SummaryInstalls bash, fish, and zsh completions in the Nix package.
Reviews (1) · Last reviewed commit: "feat(nix): install shell completions" · Reviewed by Greptile |
The Nix package shipped only
bin/, so shells never got sofka's completions.postInstallrunssofka completion bash|fish|zshand installs the output withinstallShellCompletion. It is skipped when cross-compiling.installShellFilesgoes on the final package only.commonArgsis unchanged, so the cached dependency build stays the same.Checked:
nix build .#sofkaproducesshare/{bash-completion,fish/vendor_completions.d,zsh/site-functions}. The fish script parses withfish -n.