Merge pull request #45784 from oxij/pull/44720-shell-env-edited
nixos/shells: Avoid overriding the environment for other child shells
This commit is contained in:
commit
5fc8ebdda0
@ -163,15 +163,24 @@ in
|
|||||||
/bin/sh
|
/bin/sh
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
# For resetting environment with `. /etc/set-environment` when needed
|
||||||
|
# and discoverability (see motivation of #30418).
|
||||||
|
environment.etc."set-environment".source = config.system.build.setEnvironment;
|
||||||
|
|
||||||
system.build.setEnvironment = pkgs.writeText "set-environment"
|
system.build.setEnvironment = pkgs.writeText "set-environment"
|
||||||
''
|
''
|
||||||
${exportedEnvVars}
|
# DO NOT EDIT -- this file has been generated automatically.
|
||||||
|
|
||||||
${cfg.extraInit}
|
# Prevent this file from being sourced by child shells.
|
||||||
|
export __NIXOS_SET_ENVIRONMENT_DONE=1
|
||||||
|
|
||||||
# ~/bin if it exists overrides other bin directories.
|
${exportedEnvVars}
|
||||||
export PATH="$HOME/bin:$PATH"
|
|
||||||
'';
|
${cfg.extraInit}
|
||||||
|
|
||||||
|
# ~/bin if it exists overrides other bin directories.
|
||||||
|
export PATH="$HOME/bin:$PATH"
|
||||||
|
'';
|
||||||
|
|
||||||
system.activationScripts.binsh = stringAfter [ "stdio" ]
|
system.activationScripts.binsh = stringAfter [ "stdio" ]
|
||||||
''
|
''
|
||||||
|
@ -126,7 +126,9 @@ in
|
|||||||
programs.bash = {
|
programs.bash = {
|
||||||
|
|
||||||
shellInit = ''
|
shellInit = ''
|
||||||
${config.system.build.setEnvironment.text}
|
if [ -z "$__NIXOS_SET_ENVIRONMENT_DONE" ]; then
|
||||||
|
. ${config.system.build.setEnvironment}
|
||||||
|
fi
|
||||||
|
|
||||||
${cfge.shellInit}
|
${cfge.shellInit}
|
||||||
'';
|
'';
|
||||||
@ -166,11 +168,11 @@ in
|
|||||||
|
|
||||||
# Read system-wide modifications.
|
# Read system-wide modifications.
|
||||||
if test -f /etc/profile.local; then
|
if test -f /etc/profile.local; then
|
||||||
. /etc/profile.local
|
. /etc/profile.local
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "''${BASH_VERSION:-}" ]; then
|
if [ -n "''${BASH_VERSION:-}" ]; then
|
||||||
. /etc/bashrc
|
. /etc/bashrc
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
@ -191,12 +193,12 @@ in
|
|||||||
|
|
||||||
# We are not always an interactive shell.
|
# We are not always an interactive shell.
|
||||||
if [ -n "$PS1" ]; then
|
if [ -n "$PS1" ]; then
|
||||||
${cfg.interactiveShellInit}
|
${cfg.interactiveShellInit}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Read system-wide modifications.
|
# Read system-wide modifications.
|
||||||
if test -f /etc/bashrc.local; then
|
if test -f /etc/bashrc.local; then
|
||||||
. /etc/bashrc.local
|
. /etc/bashrc.local
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
@ -109,7 +109,9 @@ in
|
|||||||
set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $__fish_datadir/functions
|
set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $__fish_datadir/functions
|
||||||
|
|
||||||
# source the NixOS environment config
|
# source the NixOS environment config
|
||||||
fenv source ${config.system.build.setEnvironment}
|
if [ -z "$__NIXOS_SET_ENVIRONMENT_DONE" ]
|
||||||
|
fenv source ${config.system.build.setEnvironment}
|
||||||
|
end
|
||||||
|
|
||||||
# clear fish_function_path so that it will be correctly set when we return to $__fish_datadir/config.fish
|
# clear fish_function_path so that it will be correctly set when we return to $__fish_datadir/config.fish
|
||||||
set -e fish_function_path
|
set -e fish_function_path
|
||||||
@ -150,7 +152,6 @@ in
|
|||||||
and begin
|
and begin
|
||||||
${fishAliases}
|
${fishAliases}
|
||||||
|
|
||||||
|
|
||||||
set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $fish_function_path
|
set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $fish_function_path
|
||||||
fenv source /etc/fish/foreign-env/interactiveShellInit > /dev/null
|
fenv source /etc/fish/foreign-env/interactiveShellInit > /dev/null
|
||||||
set -e fish_function_path[1]
|
set -e fish_function_path[1]
|
||||||
|
@ -70,7 +70,7 @@ in
|
|||||||
promptInit = mkOption {
|
promptInit = mkOption {
|
||||||
default = ''
|
default = ''
|
||||||
if [ "$TERM" != dumb ]; then
|
if [ "$TERM" != dumb ]; then
|
||||||
autoload -U promptinit && promptinit && prompt walters
|
autoload -U promptinit && promptinit && prompt walters
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
description = ''
|
description = ''
|
||||||
@ -116,7 +116,9 @@ in
|
|||||||
if [ -n "$__ETC_ZSHENV_SOURCED" ]; then return; fi
|
if [ -n "$__ETC_ZSHENV_SOURCED" ]; then return; fi
|
||||||
export __ETC_ZSHENV_SOURCED=1
|
export __ETC_ZSHENV_SOURCED=1
|
||||||
|
|
||||||
${config.system.build.setEnvironment.text}
|
if [ -z "$__NIXOS_SET_ENVIRONMENT_DONE" ]; then
|
||||||
|
. ${config.system.build.setEnvironment}
|
||||||
|
fi
|
||||||
|
|
||||||
${cfge.shellInit}
|
${cfge.shellInit}
|
||||||
|
|
||||||
@ -124,7 +126,7 @@ in
|
|||||||
|
|
||||||
# Read system-wide modifications.
|
# Read system-wide modifications.
|
||||||
if test -f /etc/zshenv.local; then
|
if test -f /etc/zshenv.local; then
|
||||||
. /etc/zshenv.local
|
. /etc/zshenv.local
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
@ -143,7 +145,7 @@ in
|
|||||||
|
|
||||||
# Read system-wide modifications.
|
# Read system-wide modifications.
|
||||||
if test -f /etc/zprofile.local; then
|
if test -f /etc/zprofile.local; then
|
||||||
. /etc/zprofile.local
|
. /etc/zprofile.local
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
@ -169,7 +171,7 @@ in
|
|||||||
|
|
||||||
# Tell zsh how to find installed completions
|
# Tell zsh how to find installed completions
|
||||||
for p in ''${(z)NIX_PROFILES}; do
|
for p in ''${(z)NIX_PROFILES}; do
|
||||||
fpath+=($p/share/zsh/site-functions $p/share/zsh/$ZSH_VERSION/functions $p/share/zsh/vendor-completions)
|
fpath+=($p/share/zsh/site-functions $p/share/zsh/$ZSH_VERSION/functions $p/share/zsh/vendor-completions)
|
||||||
done
|
done
|
||||||
|
|
||||||
${optionalString cfg.enableGlobalCompInit "autoload -U compinit && compinit"}
|
${optionalString cfg.enableGlobalCompInit "autoload -U compinit && compinit"}
|
||||||
@ -184,7 +186,7 @@ in
|
|||||||
|
|
||||||
# Read system-wide modifications.
|
# Read system-wide modifications.
|
||||||
if test -f /etc/zshrc.local; then
|
if test -f /etc/zshrc.local; then
|
||||||
. /etc/zshrc.local
|
. /etc/zshrc.local
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user