nixos/shells: Avoid overriding the environment for other child shells#45784
Merged
xeji merged 2 commits intoNixOS:masterfrom Sep 6, 2018
Merged
nixos/shells: Avoid overriding the environment for other child shells#45784xeji merged 2 commits intoNixOS:masterfrom
xeji merged 2 commits intoNixOS:masterfrom
Conversation
A shared exported guard `__NIXOS_SET_ENVIRONMENT_DONE` is introduced that can be used to prevent child shells from sourcing `system.build.setEnvironment` the second time. This fixes e.g. `nix run derivation` when run from e.g. ZSH through the console or ssh. Before this Bash would resource the common environment resetting the `PATH` environment variable. We also export `system.build.setEnvironment` to `/etc/set-environment` making it easy to reset the common environment with `. /etc/set-environment` when needed and to grep for environment variables in `/etc` (which was the motivation of NixOS#30418). This reverts changes made in b00a3fc (the original NixOS#30418).
to comply with `doc/coding-conventions.xml`
9 tasks
Member
|
What if someone wants to |
Mic92
reviewed
Aug 30, 2018
|
|
||
| # For resetting environment with `. /etc/set-environment` when needed | ||
| # and discoverability (see motivation of #30418). | ||
| environment.etc."set-environment".source = config.system.build.setEnvironment; |
Member
There was a problem hiding this comment.
Ah I see. This should be documented for sure!
Member
Author
Everything would stay as it was before this PR as it sets |
6 tasks
Member
Author
|
ping?
I agree that the new `/etc` thing should be documented somewhere, but I don't see a good place in the manual where to put it, and I'm not feeling like making one right now.
|
Contributor
|
This does fix a rather unfortunate bug with |
Contributor
Member
Author
|
Yes, you're right, it should.
|
Contributor
|
Everything seems to be working correctly, no problem so far. |
Member
Author
Contributor
Contributor
|
done |
Member
Author
8 tasks
hedning
added a commit
to hedning/nixpkgs
that referenced
this pull request
Oct 16, 2018
When GDM launches a new session it will inherit the user's systemd environment (but only unset variables). If `__NIXOS_SET_ENVIRONMENT_DONE` is set in the user's systemd environment it will prevent the environment to be set properly or updated (eg. after having done a system rebuild). Gnome sessions exports their environment to systemd at startup. If something is keeping the user's systemd process alive (eg. ssh) launching a new gnome session after logging out will result in a broken PATH. Specifically the PATH will be inherited from GDM and never reset. We patch GDM to never inherit `__NIXOS_SET_ENVIRONMENT_DONE` so new sessions will always reset their base environment. fixes NixOS#48255 For more info about the environment setup: NixOS#45784
jian-lin
added a commit
to linj-fork/home-manager
that referenced
this pull request
Feb 8, 2022
This patch moves both home.sessionVariables and programs.zsh.sessionVariables from .zshrc to .zshenv. Additionally, these two kinds of session variables will not be sourced more than once to allow user-customized ones to take effect. Before, session variables are in .zshrc, which causes non-interactive shells to not be able to get those variables. For example, running a command through SSH is in a non-interactive and non-login shell, which suffers from this. With this patch, all kinds of shells can get session variables. The reason why these session variables are not moved to .zprofile is that programs started by systemd user instances are not able to get variables defined in that file. For example, GNOME Terminal (gnome-terminal-server.service) is one of these programs and doesn't get variables defined in .zprofile. As a result, the shells it starts, which are interactive and non-login, do not get those variables. Fixes nix-community#2445 Related NixOS/nixpkgs#33219 Related NixOS/nixpkgs#45784
7 tasks
jian-lin
added a commit
to linj-fork/home-manager
that referenced
this pull request
Feb 8, 2022
This patch moves both home.sessionVariables and programs.zsh.sessionVariables from .zshrc to .zshenv. Additionally, these two kinds of session variables will not be sourced more than once to allow user-customized ones to take effect. Before, session variables are in .zshrc, which causes non-interactive shells to not be able to get those variables. For example, running a command through SSH is in a non-interactive and non-login shell, which suffers from this. With this patch, all kinds of shells can get session variables. The reason why these session variables are not moved to .zprofile is that programs started by systemd user instances are not able to get variables defined in that file. For example, GNOME Terminal (gnome-terminal-server.service) is one of these programs and doesn't get variables defined in .zprofile. As a result, the shells it starts, which are interactive and non-login, do not get those variables. Fixes nix-community#2445 Related NixOS/nixpkgs#33219 Related NixOS/nixpkgs#45784
jian-lin
added a commit
to linj-fork/home-manager
that referenced
this pull request
Feb 8, 2022
This patch moves both home.sessionVariables and programs.zsh.sessionVariables from .zshrc to .zshenv. Additionally, these two kinds of session variables will not be sourced more than once to allow user-customized ones to take effect. Before, session variables are in .zshrc, which causes non-interactive shells to not be able to get those variables. For example, running a command through SSH is in a non-interactive and non-login shell, which suffers from this. With this patch, all kinds of shells can get session variables. The reason why these session variables are not moved to .zprofile is that programs started by systemd user instances are not able to get variables defined in that file. For example, GNOME Terminal (gnome-terminal-server.service) is one of these programs and doesn't get variables defined in .zprofile. As a result, the shells it starts, which are interactive and non-login, do not get those variables. Fixes nix-community#2445 Related NixOS/nixpkgs#33219 Related NixOS/nixpkgs#45784
teto
pushed a commit
to teto/home-manager
that referenced
this pull request
Feb 17, 2022
This patch moves both home.sessionVariables and programs.zsh.sessionVariables from .zshrc to .zshenv. Additionally, these two kinds of session variables will not be sourced more than once to allow user-customized ones to take effect. Before, session variables are in .zshrc, which causes non-interactive shells to not be able to get those variables. For example, running a command through SSH is in a non-interactive and non-login shell, which suffers from this. With this patch, all kinds of shells can get session variables. The reason why these session variables are not moved to .zprofile is that programs started by systemd user instances are not able to get variables defined in that file. For example, GNOME Terminal (gnome-terminal-server.service) is one of these programs and doesn't get variables defined in .zprofile. As a result, the shells it starts, which are interactive and non-login, do not get those variables. Fixes nix-community#2445 Related NixOS/nixpkgs#33219 Related NixOS/nixpkgs#45784
teto
pushed a commit
to nix-community/home-manager
that referenced
this pull request
Feb 17, 2022
This patch moves both home.sessionVariables and programs.zsh.sessionVariables from .zshrc to .zshenv. Additionally, these two kinds of session variables will not be sourced more than once to allow user-customized ones to take effect. Before, session variables are in .zshrc, which causes non-interactive shells to not be able to get those variables. For example, running a command through SSH is in a non-interactive and non-login shell, which suffers from this. With this patch, all kinds of shells can get session variables. The reason why these session variables are not moved to .zprofile is that programs started by systemd user instances are not able to get variables defined in that file. For example, GNOME Terminal (gnome-terminal-server.service) is one of these programs and doesn't get variables defined in .zprofile. As a result, the shells it starts, which are interactive and non-login, do not get those variables. Fixes #2445 Related NixOS/nixpkgs#33219 Related NixOS/nixpkgs#45784 This file is not formatted before and is excluded by ./format, so I don't format it.
jian-lin
added a commit
to linj-fork/home-manager
that referenced
this pull request
Feb 21, 2022
This patch moves both home.sessionVariables and programs.zsh.sessionVariables from .zshrc to .zshenv. Additionally, these two kinds of session variables will not be sourced more than once to allow user-customized ones to take effect. Before, session variables are in .zshrc, which causes non-interactive shells to not be able to get those variables. For example, running a command through SSH is in a non-interactive and non-login shell, which suffers from this. With this patch, all kinds of shells can get session variables. The reason why these session variables are not moved to .zprofile is that programs started by systemd user instances are not able to get variables defined in that file. For example, GNOME Terminal (gnome-terminal-server.service) is one of these programs and doesn't get variables defined in .zprofile. As a result, the shells it starts, which are interactive and non-login, do not get those variables. Fixes nix-community#2445 Related NixOS/nixpkgs#33219 Related NixOS/nixpkgs#45784
teto
pushed a commit
to teto/home-manager
that referenced
this pull request
Aug 22, 2022
This patch moves both home.sessionVariables and programs.zsh.sessionVariables from .zshrc to .zshenv. Additionally, these two kinds of session variables will not be sourced more than once to allow user-customized ones to take effect. Before, session variables are in .zshrc, which causes non-interactive shells to not be able to get those variables. For example, running a command through SSH is in a non-interactive and non-login shell, which suffers from this. With this patch, all kinds of shells can get session variables. The reason why these session variables are not moved to .zprofile is that programs started by systemd user instances are not able to get variables defined in that file. For example, GNOME Terminal (gnome-terminal-server.service) is one of these programs and doesn't get variables defined in .zprofile. As a result, the shells it starts, which are interactive and non-login, do not get those variables. Fixes nix-community#2445 Related NixOS/nixpkgs#33219 Related NixOS/nixpkgs#45784 This file is not formatted before and is excluded by ./format, so I don't format it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation for this change
An edited version of #44720.
Things done
/cc @LnL7 @pxc @rnhmjoj from git-blame