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

poor first-use experience due to missing "complete", etc. #8764

Open
stevegt opened this issue Jul 31, 2023 · 3 comments
Open

poor first-use experience due to missing "complete", etc. #8764

stevegt opened this issue Jul 31, 2023 · 3 comments
Labels

Comments

@stevegt
Copy link

stevegt commented Jul 31, 2023

All right y'all. This noninteractive bash default thing really ought to be fixed; if a fix in code isn't viable, then I'll be happy to take this over to the nix.dev repo and fix it in the "first steps" page -- let me know. As things stand right now, I've just now thrashed around for too long myself without finding a clear answer. Any reasonably experienced UNIX or Linux user is going to have bash completion scripts sourced from their .bashrc, they are going to run smack into this error on first use, and they are going to want to learn the idiomatic way to correct it.

I could keep thrashing around and come up with a solution that works for me on my own machine, but after years of being referred to in print as being a fellow traveler in the concepts behind nix and NixOS, I kinda want to make sure other new users have a better experience than this. I'm glad I finally found an excuse to start playing with nix -- I'm impressed by the quality of the nixos.org and nix.dev sites otherwise, but this completion error thing seems like a glaring omission.

Background

Install appeared okay other than seeing a pile of 'complete' errors when running nix-shell -p nix-info --run "nix-info -m" at the end. Then while following https://nix.dev/tutorials/first-steps/ad-hoc-shell-environments I ran into this:

$ nix-env --version
nix-env (Nix) 2.17.0
$ nix-shell -p cowsay lolcat

[nix-shell:~]$ cowsay foo
/home/stevegt/lab/google/google-cloud-sdk/completion.bash.inc: line 56: complete: command not found
/home/stevegt/lab/google/google-cloud-sdk/completion.bash.inc: line 81: complete: command not found
/home/stevegt/lab/google/google-cloud-sdk/completion.bash.inc: line 82: complete: command not found
/home/stevegt/bin/gocd-completion: line 60: complete: command not found
/home/stevegt/bin/gocd-completion: line 61: complete: command not found
/home/stevegt/.sdkman/contrib/completion/bash/sdk: line 82: complete: command not found
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
        LANGUAGE = (unset),
        LC_ALL = (unset),
        LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
 _____ 
< foo >
 ----- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

I'm ignoring the perl error for now -- I'll deal with that myself.

Observations

The word "complete" does not appear on https://nix.dev/tutorials/first-steps/ad-hoc-shell-environments at all, which is where most folks will start trying to troubleshoot the problem.

After digging around in #730, #4254, #6091, #6982, and even reddit, I still don't have a clear idea of what a user is supposed to do to avoid getting these errors when running the tutorial. I see comments like "just use bashInteractive" mentioned several times, but a new nix user won't know what that means.

I've spent an hour or so on this myself so far, including taking the time to write this bug.

Question

Can anyone provide a clear, concise, idiomatic way to get rid of the 'complete' errors? If not a code change, then at least text suitable for inserting into the "first steps" tutorial?

The only thing I've thought of so far, given my own lack of experience with nix, is to wrap my .bashrc completion includes in an if statement that checks to see if IN_NIX_SHELL is set. Is that what we want to expect new users to do, or is there a better way?

@stevegt stevegt added the bug label Jul 31, 2023
@abathur
Copy link
Member

abathur commented Aug 1, 2023

What happens if you run nix-shell -p cowsay lolcat --pure --command 'complete -p'? And try again without --pure?

I suspect you're in a bit of a hall of mirrors. bash vs bashInteractive is weird for historical reasons in nixpkgs--but it shouldn't have much to do with what's going on here. AFAIK nix-shell will use bashInteractive itself, so completions should be working. Could something in your shell init files be interfering--perhaps by running some other shell?

It might also be interesting to see what lsof -p $$ from inside the shell has to say.

@stevegt
Copy link
Author

stevegt commented Aug 2, 2023

Hi @abathur -- you've given me some ideas, both for fixing my own situation and for language that could go into the first-steps tutorial, something like:

If you are seeing nix-shell errors related to bash completion or other oddities, make sure you have your .bash_profile and .bashrc set up right. Login stuff goes in the former and non-login in the latter. It also might make sense to migrate any noninteractive stuff to a .bash_env file and set BASH_ENV to point at that (rather than e.g. .bashrc). Nix and the nix install assume that all of this is done right, which may not be the case if you have an older environment that has grown weeds. For more information, see the INVOCATION section of the bash(1) man page.

I'm still cleaning up a few decade's worth of weeds in my own dotfiles -- some of the stuff in there dates back to pre-bash Korn shell days. For the record, answering your questions:

$ nix-shell -p cowsay lolcat --pure --command 'complete -p'
# no output

$ nix-shell -p cowsay lolcat --command 'complete -p'
complete -o default -F _sdk sdk
complete -o nospace -F _python_argcomplete gcloud
complete -F _gocd_completion cdgo
complete -F _gocd_completion gocd
complete -F _bq_completer bq
complete -o nospace -F _python_argcomplete gsutil

This led me to try this, which provided a major clue:

$ nix-shell -p cowsay lolcat --pure 
[nix-shell:~]$ cowsay slkdajflsakfdj 
 ________________ 
< slkdajflsakfdj >
 ---------------- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

[nix-shell:~]$ 
exit

$ echo $BASH_ENV
/home/stevegt/.bashrc

$ nix-shell -p cowsay lolcat --pure --keep BASH_ENV
[nix-shell:~]$ cowsay lsakfdj lj
/home/stevegt/lab/google/google-cloud-sdk/completion.bash.inc: line 56: complete: command not found
/home/stevegt/lab/google/google-cloud-sdk/completion.bash.inc: line 81: complete: command not found
/home/stevegt/lab/google/google-cloud-sdk/completion.bash.inc: line 82: complete: command not found
/home/stevegt/.pyenv/libexec/../completions/pyenv.bash: line 16: complete: command not found
/home/stevegt/.goenv/libexec/../completions/goenv.bash: line 16: complete: command not found
/home/stevegt/bin/gocd-completion: line 60: complete: command not found
/home/stevegt/bin/gocd-completion: line 61: complete: command not found
/home/stevegt/.sdkman/contrib/completion/bash/sdk: line 82: complete: command not found
 ____________ 
< lsakfdj lj >
 ------------ 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

I have some 'complete' commands in scripts that are sourced from .bashrc. Something in nix's invocation of 'cowsay' is apparently running a noninteractive bash, and because BASH_ENV is set to .bashrc, those 'complete' commands are being attempted.

Still looking.

@abathur
Copy link
Member

abathur commented Aug 2, 2023

Something in nix's invocation of 'cowsay' is apparently running a noninteractive bash, and because BASH_ENV is set to .bashrc, those 'complete' commands are being attempted.

That might explain it. Yes, generally scripts/wrappers use the non-interactive bash (such wrappers are common in the ecosystem and cowsay is wrapped: https://github.com/NixOS/nixpkgs/blob/9d10b637e46e87fd3dcb40402ea6418e60ac433c/pkgs/tools/misc/cowsay/default.nix#L29).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants