NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.64k stars 1.51k forks source link

Bash completion in nix-shell -p (also solving support for strictDeps by default) #4254

Open roberth opened 3 years ago

roberth commented 3 years ago

Is your feature request related to a problem? Please describe.

nix-shell doesn't currently provide bash completion for new commands that provide their own completion scripts. https://github.com/NixOS/nixpkgs/pull/103501 aims to change that, but can't support completions in nix-shell -p because that command adds to the wrong attribute, buildInputs instead of nativeBuildInputs.

Describe the solution you'd like

nix-shell should set nativeBuildInputs (one way or another).

This aligns with having strictDeps by default (which is not a requirement though). StrictDeps enforces desirable properties like outputs not retaining references to build tools. It also prevents mistakes that break cross-compilation.

We can pick from these designs or think of something better.

principled scheme

-p sets both and emits a warning --tool adds to nativeBuildInputs --input adds to buildInputs

minimal scheme

-p sets nativeBuildInputs --input adds to buildInputs

With the minimal scheme we don't have to update all documentation to change -ps to --tools, but it will silently break some nix-shell invocations.

compatible scheme

Like the principled scheme but without the warning. Does nothing to help towards strictDeps.

Describe alternatives you've considered

Also add buildInputs to XDG_DATA_DIRS, but this "non-strictDeps" behavior is risky, potentially affecting any build in Nixpkgs.

Additional context

matthewbauer commented 3 years ago

See also https://github.com/NixOS/nix/pull/2504

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

roberth commented 3 years ago

stable bot: Still broken.

A solution is available https://github.com/NixOS/nix/pull/4452. If a maintainer agrees with the design, I'll happily rebase it. Otherwise, I can implement any suggestions.

stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info

roberth commented 2 years ago

A solution is available #4452. If a maintainer agrees with the design, I'll happily rebase it. Otherwise, I can implement any suggestions.

stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info

bjornfor commented 2 years ago

Not stale.

(I generally don't "unstale" issues, but I think I saw another Nix issue being closed by the Stale bot today, and I don't want that to happen.)

gaima8 commented 1 year ago

Sorry, complete nix noob here. Does this issue, and related PR, prevent the lack of _get_comp_words_by_ref, etc, in nix-shell shells?

With a shellHook in my shell.nix running

source <(kubectl completion bash)

when trying to complete kubectl commands beginning with c I get;

[nix-shell:~]$ kubectl cbash: _get_comp_words_by_ref: command not found

Although if I install bash-completion and then manually source /nix/store/....-bash-completion-2.11/etc/profile.d/bash_completion.sh inside the nix-shell I get an additional 72 functions declared, including _get_comp_words_by_ref, and bash completion for kubectl I made the shell load and all the other builtin-it/included completions (wget, etc) function perfectly.

[nix-shell:~]$ declare -F | grep _get

[nix-shell:~]$ source /nix/store/jm0zjy8chipraqchwprgs15ajp705cin-bash-completion-2.11/etc/profile.d/bash_completion.sh 

[nix-shell:~]$ declare -F | grep _get
declare -f __get_cword_at_cursor_by_ref
declare -f _get_comp_words_by_ref
declare -f _get_cword
declare -f _get_first_arg
declare -f _get_pword

[nix-shell:~]$