Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
roberth opened this issue Nov 13, 2020 · 8 comments

Comments

@roberth
Copy link
Member

roberth commented Nov 13, 2020

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.
NixOS/nixpkgs#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
Copy link
Member

See also #2504

@stale
Copy link

stale bot commented Jun 2, 2021

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

@stale stale bot added the stale label Jun 2, 2021
@roberth
Copy link
Member Author

roberth commented Jun 2, 2021

stable bot: Still broken.

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

@stale
Copy link

stale bot commented Jan 8, 2022

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

@stale stale bot added the stale label Jan 8, 2022
@roberth
Copy link
Member Author

roberth commented Jan 9, 2022

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

@stale stale bot removed the stale label Jan 9, 2022
@stale
Copy link

stale bot commented Jul 10, 2022

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

@stale stale bot added the stale label Jul 10, 2022
@bjornfor
Copy link
Contributor

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.)

@stale stale bot removed the stale label Jul 10, 2022
@gaima8
Copy link

gaima8 commented Nov 7, 2022

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:~]$ 

BronzeDeer added a commit to BronzeDeer/zsh-completion-sync that referenced this issue Sep 22, 2024
Currently, our $XDG_DATA_DIRs and $FPATH solution does not help with the
default behaviour of nix-shell [-p], which spawns a full shell,
obliviating some need for $FPATH modification post shell start, but
which does not export the `share/` of packages, (pending resolution of
NixOS/nix#4254) and therefore will not be able
to provide completions at all.

This commit adds an optional workaround feature which attempts to detect
nix `share/` paths based on the bin directories on `$PATH`. It is
disabled by default, since this is abusing $PATH for something it is not
meant for. However, in practice, it is incredibly unlikely that this
will detect any directories that shouldn't be there anyway.
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 a pull request may close this issue.

5 participants