-
-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
zsh: set environment variables in zshenv instead of zprofile #217205
Conversation
An explanation for home-manager issues: nix-community/home-manager#3681 (comment). |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/home-manager-doesnt-seem-to-recognize-sessionvariables/8488/25 |
In short, when system-level |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/prs-ready-for-review/3032/1868 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM although I don't have any familiarity with this corner of nixpkgs
Can we merge this? Or is there anything else I need to do? |
I know nothing about zsh and is not confident enough about this. Could any real zsh user provide some opinions? |
9b5ff78
to
878c20d
Compare
A release note is added as requested by @Mic92. IMHO, it's ready to be merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this to my nixos-config and can confirm that it fixed the issue I reported originally in nix-community/home-manager@2116fe6#r67182173
pkgs/shells/zsh/default.nix
Outdated
if test -r /etc/zprofile; then | ||
. /etc/zprofile | ||
if test -r /etc/zshenv; then | ||
. /etc/zshenv | ||
else | ||
emulate bash | ||
alias shopt=false | ||
. /etc/profile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My motivation of this pr is to solve the issue that env vars set in .zshenv
are overridden by those in /etc/set-environment
($out/etc/zprofile
sources /etc/profile
which sources /etc/set-environment
) on NixOS system with programs.zsh.enable = false
. This issue comes from users of home-manager.
I can think of three proposals to deal with this issue:
Proposal 0: souce /etc/profile
in $out/etc/zprofile
, i.e., the old behaviour
- Pros
config.environment.loginShellInit
is sourced in login zsh
- Cons
- env vars set in
.zshenv
are overridden by those in/etc/set-environment
config.environment.shellInit
is not sourced in non-login zshconfig.programs.bash.shellInit
is also sourced in login zshconfig.programs.bash.loginShellInit
is also sourced in login zsh
- env vars set in
Proposal 1: souce /etc/profile
in $out/etc/zshenv
, i.e., what this patch currently dose
- Pros
- env vars set in
.zshenv
are not overridden by those in/etc/set-environment
config.environment.shellInit
is sourced in all zsh
- env vars set in
- Cons
config.environment.loginShellInit
is also sourced in non-login zshconfig.programs.bash.shellInit
is also sourced in all zshconfig.programs.bash.loginShellInit
is also sourced in all zsh
Proposal 2: souce /etc/set-environment
in $out/etc/zshenv
- Pros
- env vars set in
.zshenv
are not overridden by those in/etc/set-environment
config.programs.bash.shellInit
is not sourced in any zshconfig.programs.bash.loginShellInit
is not sourced in any zsh
- env vars set in
- Cons
config.environment.shellInit
is not sourced in any zshconfig.environment.loginShellInit
is not sourced in any zsh
I prefer proposal 2 because it fixes the issue without any wrong behaviour, i.e., sourcing config of bash. If you want those shell configs in config.environment
, just set programs.zsh.enable
.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think proposal 2 sounds more reasonable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed to proposal 2.
878c20d
to
e23762c
Compare
This patch fixes two issues: 1. The file in which environment variables are set is inconsistent. - This file sets them in zprofile when programs.zsh.enable is not set. - Zsh module sets them in zshenv when programs.zsh.enable is set. 2. Setting environment variables in zprofile overrides what users set in .zshenv. See these[1] home-manager[2] issues[3]. /etc/profile is also changed to /etc/set-environment. Here is a comparison: Using /etc/profile: - Pros - config.environment.shellInit is sourced in all zsh - Cons - config.environment.loginShellInit is also sourced in non-login zsh - config.programs.bash.shellInit is also sourced in all zsh - config.programs.bash.loginShellInit is also sourced in all zsh Using /etc/set-environment: - Pros - config.programs.bash.shellInit is not sourced in any zsh - config.programs.bash.loginShellInit is not sourced in any zsh - Cons - config.environment.shellInit is not sourced in any zsh - config.environment.loginShellInit is not sourced in any zsh [1]: nix-community/home-manager#2751 (comment) [2]: nix-community/home-manager#2991 [3]: nix-community/home-manager#3681 (comment)
e23762c
to
8e2e741
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works again.
A friendly ping @Mic92 |
This will probably break the existing zsh configurations of some people, right? |
For users who set their shell to zsh and do not enable the system-level zsh module, yes, there are changed behaviours listed in the proposal 2. I have added a release note for that. That should be enough, right? |
We should really remove the generic |
FWIW this totally broke zsh for me, every new shell was sourcing Adding (I haven't investigated this deeply at all, but the ❯ cat /nix/store/z2cnzz34sqrk8zwqq2g7sq0pfj8kk6j8-zsh-5.9/etc/zshenv_zwc_is_used
if test -e /etc/NIXOS; then
if test -r /etc/zshenv; then
. /etc/zshenv
else
emulate bash
alias shopt=false
if [ -z "" ]; then
. /etc/set-environment
fi
unalias shopt
emulate zsh
fi
if test -r /etc/zshenv.local; then
. /etc/zshenv.local
fi
else
# on non-nixos we just source the global /etc/zshenv as if we did
# not use the configure flag
if test -r /etc/zshenv; then
. /etc/zshenv
fi
fi |
@expipiplus1 Thanks! Fixed in #223696. |
Thanks! |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/home-manager-not-setting-sessionvariables-or-shellaliases/33947/2 |
This patch fixes two issues:
Description of changes
Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)