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

Warn if bash is not installed #30

Open
robertmassaioli opened this issue Jan 11, 2022 · 9 comments
Open

Warn if bash is not installed #30

robertmassaioli opened this issue Jan 11, 2022 · 9 comments

Comments

@robertmassaioli
Copy link

Issue description

When bash was not installed, I got this error:

╭─ ~/.zsh-custom/plugins/nix-shell on master✔ 22-01-12 - 10:31:31 [0]
╰─⠠⠵ nix-shell -p myHaskellEnv
/nix/store/1fyqjwakpb5d8h52bwad3inn1r2zndhj-stdenv-darwin/setup: line 20: shopt: inherit_errexit: invalid shell option name
/private/tmp/nix-shell-23306-0/rc: line 1: rm: No such file or directory

I then ran brew install bash and it fixed things:

╭─ ~/.zsh-custom/plugins/nix-shell on master✔ 22-01-12 - 10:31:39 [1]
╰─⠠⠵ brew install bash
Running `brew update --preinstall`...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
Updated 1 formula.

==> Downloading https://ghcr.io/v2/homebrew/core/bash/manifests/5.1.16
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/bash/blobs/sha256:85ac02733b659f4a7884395ed2cfd7dbdf59999a0d8a434a0c1a75085009ce2a
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:85ac02733b659f4a7884395ed2cfd7dbdf59999a0d8a434a0c1a75085009ce2a?se=2022-01-11T23%3A40%3A00Z&sig=cGTa65Ck9peapQv9%2FDEs8QMrSWFKGWzkoEXgA2lpW
######################################################################## 100.0%
==> Pouring bash--5.1.16.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/bash/5.1.16: 157 files, 10.9MB
==> Running `brew cleanup bash`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
╭─ ~/.zsh-custom/plugins/nix-shell on master✔ 22-01-12 - 10:32:35 [0]

I highly recommend that a note be added to the readme for this use case. I have not investigated further why this is happening.

@chisui
Copy link
Owner

chisui commented Jan 12, 2022

please add additional information to the ticket as specified in the template. In addition MacOS support is limited since I don't have the ability to test code on MacOS.


Does nix-shell work if you don't use this plugin?

@matejcik
Copy link

i'm seeing the same issue.
yes, nix-shell works without the plugin. it also starts working as soon as bash is installed

chisui added a commit that referenced this issue Mar 31, 2022
@chisui
Copy link
Owner

chisui commented Mar 31, 2022

Ah, I forgot that I called bash explicitly in the code. I added a Warning message. Does v0.5.0 print Warning if bash is not installed?

@matejcik
Copy link

matejcik commented Apr 1, 2022

on commit af6f8a2, no warning message is shown.

@matejcik
Copy link

matejcik commented Apr 1, 2022

no, wait, the problem is that there is bash available, but it's version 3.2 so maybe too old? it doesn't know shopt inherit_errexit

Honestly not sure what to do here. You could detect bash version I suppose, but that sounds like a weird solution?
Alternately detect that you're on a Mac and that bash is /bin/bash, like:

if [ $(uname -s) == "Darwin" && $(which /bin/bash) == "/bin/bash"]; then
  echo "pls install newer bash via homebrew"
fi

The shopt call comes from nix itself so no way for us to modify that.

@matejcik
Copy link

matejcik commented Apr 1, 2022

maybe easiest to mention the problem in README and point to a solution there, so that it's easy to google.

@chisui
Copy link
Owner

chisui commented Apr 3, 2022

Could you post the output of bash --version for the preinstalled bash?


I'm thinking of another solution like this right now:

if [ -z ${ZSH_NIX_SHELL_BASH_OVERRIDE+x}  &&  $(uname -s) == "Darwin" && $(bash --version | grep -q "3.2") ]; then
  echo "A well written warning"
  export ZSH_NIX_SHELL_BASH_OVERRIDE="command nix-shell -p bash --command"
fi

and then using that override in the shim.

@matejcik
Copy link

matejcik commented Apr 4, 2022

$ /bin/bash --version
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin21)
Copyright (C) 2007 Free Software Foundation, Inc.

I can't say it's a good idea to rely on the exact string though -- an OS update could easily changed, this is on MacOS Monterey but I don't know about older versions, etc.

@chisui
Copy link
Owner

chisui commented Apr 4, 2022

As far as I understand the bash license changed at some point and this is the latest Version Apple is allowed to ship with MacOS. So I don't think that either the 3.2 part nor the (c) 2007 part will change.

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

No branches or pull requests

3 participants