-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Multi-user Nix install doesn't initialize for non-interactive login bash shell on macOS #4376
Comments
I spent a little time on a few different occasions recently going through issues to figure out what the existing PR might be able to close. While looking over the Nth shell-setup problem (but also, seeing the regular stream of these in IRC/discourse) I wondered if the installer can/should proactively test and report on the shell configurations at the end (perhaps with context/nudge for reporting any that fail)? |
The only failure I'm aware of when setting up shell configurations is in the single-user approach if none of The more common scenario AIUI is macOS updates wiping out the |
Not sure I phrased that well. By proactively testing, I mean literally invoke the shell and run something trivial in it--for all of the shells/configurations/options we intend to support (where any that don't initialize should fail). |
I suppose we could, but I’m not sure how much that will help with things. |
It probably doesn't help much relative to having an install-healing nix-daemon. |
This is too long ago to remember why I picked bashrc, but I think it was because profile only gets loaded for login shells. |
Interactive non-login shells load |
I marked this as stale due to inactivity. → More info |
Last I checked this was still an issue. |
This is definitely still an issue with 2.5-pre builds even. |
This is still an issue on non-interactive shell with linux
|
By not settings up the non-interactive shell, it means that nix copy --to ssh-ng://ubuntu@<ip> nixpkgs#sl
bash: nix-daemon: command not found
error: cannot open connection to remote store 'ssh-ng://ubuntu@<ip>': error: unexpected end-of-file However, when I used the Determinate Systems installer instead, everything worked. I remember seeing an issue suggesting that it might replace the current Nix installer, so maybe that's the solution. |
Describe the bug
The multi-user Nix installer will modify
/etc/bashrc
,/etc/profile.d/nix.sh
, and/etc/zshenv
to initialize itself. The/etc/profile.d/nix.sh
modification only occurs if/etc/profile.d
exists. This means that on systems that don't use/etc/profile.d
, including but not limited to macOS, the installer will only modify/etc/bashrc
and/etc/zshenv
.I'm not familiar with the zsh initialization process so I don't know if
/etc/zshenv
is sufficient there, but for Bash we really do need to put this into both the profile and the bashrc file./etc/profile
is sourced for login shells, and/etc/bashrc
is sourced for interactive login shells¹. But our goal is actually to be configured for login shells, not for interactive ones. For single-user installs we install into~/.bash_profile
,~/.bash_login
, or~/.profile
(for bash).It's not clear to me why we're targeting
/etc/bashrc
at all instead of/etc/profile
. I feel like the logic here should be "install into/etc/profile.d/nix.sh
if/etc/profile.d
exists, otherwise install into/etc/profile
". This way we'll get initialized for all login shells regardless of interactivity.Beyond not initializing for non-interactive login shells, the use of
/etc/bashrc
also means we shouldn't² be initialized forsh
shells³. Or fordash
(which acts likesh
).It looks like this was changed 3 years ago in 27788f4 by @LnL7 with the rationale "The default profile already loads /etc/bashrc". Prior to that it was installing into both
/etc/profile
and/etc/bashrc
, but there's no explanation as to why it was doing both (this dates back to the original darwin multi-user installer by @grahamc). I think this was a mistake, it should have chosen/etc/profile
instead of/etc/bashrc
.¹This describes the setup on macOS. What actually happens is
/etc/profile
sources/etc/bashrc
when running as Bash, and the latter bails early if it's not an interactive shell. Another system could do this differently, but I assume this is a standard initialization setup.²We actually are if
sh
maps tobash
, since the macOS/etc/profile
usesif [ "${BASH-no}" != "no" ]
as its guard, but Bash 3.2.57 apparently sets$BASH
to the name of the shell regardless of how it's invoked, meaning invoking it assh
still sets it to/bin/sh
. However if the user has mapped/bin/sh
to/bin/dash
or/bin/zsh
(using/private/var/select/sh
) then it won't work³Single-user install does this mostly correctly, it targets the files used by login. But if
~/.bash_profile
or~/.bash_login
exists it won't install into~/.profile
and therefore won't be sourced bysh -l
or bydash -l
. If neither of those two files exist and~/.profile
does, it will install there, and if none of them exist it instructs the user to install into~/.profile
.Steps To Reproduce
login -f $USER bash -c 'type nix'
. This gives you clean environment but runs a non-interactive login shell.login -f $USER dash -c 'type nix'
, which runs thesh
initialization. Or point your/private/var/select/sh
symlink at/bin/dash
or/bin/zsh
and runlogin -f $USER sh -c 'type nix'
.Expected behavior
All sh-compatible login shells should setup Nix.
nix-env --version
outputnix-env (Nix) 2.3.8
Additional context
I get the feeling that macOS is primarily tested in a single-user install scenario. But single-user installs on macOS are going away in #4289 so it's important that we clean this stuff up.
This issue was discovered when a macOS app I use that invokes scripts using a non-interactive login shell was unable to find Nix after I switched from single-user to multi-user install.
The text was updated successfully, but these errors were encountered: