nix-shell: Preserve the TZ variable of the user

This commit is contained in:
Eelco Dolstra 2014-01-23 13:31:29 +01:00
parent 7fdee6e136
commit 79dee4283d

View file

@ -185,7 +185,7 @@ foreach my $expr (@exprs) {
# Set the environment. # Set the environment.
if ($pure) { if ($pure) {
foreach my $name (keys %ENV) { foreach my $name (keys %ENV) {
next if grep { $_ eq $name } ("HOME", "USER", "LOGNAME", "DISPLAY", "PATH", "TERM", "IN_NIX_SHELL"); next if grep { $_ eq $name } ("HOME", "USER", "LOGNAME", "DISPLAY", "PATH", "TERM", "IN_NIX_SHELL", "TZ");
delete $ENV{$name}; delete $ENV{$name};
} }
# NixOS hack: prevent /etc/bashrc from sourcing /etc/profile. # NixOS hack: prevent /etc/bashrc from sourcing /etc/profile.
@ -207,12 +207,13 @@ foreach my $expr (@exprs) {
($pure ? '' : 'p=$PATH; ' ) . ($pure ? '' : 'p=$PATH; ' ) .
'dontAddDisableDepTrack=1; ' . 'dontAddDisableDepTrack=1; ' .
'[ -e $stdenv/setup ] && source $stdenv/setup; ' . '[ -e $stdenv/setup ] && source $stdenv/setup; ' .
($pure ? '' : 'PATH=$PATH:$p; ') . ($pure ? '' : 'PATH=$PATH:$p; unset p; ') .
'set +e; ' . 'set +e; ' .
'[ -n "$PS1" ] && PS1="\n\[\033[1;32m\][nix-shell:\w]$\[\033[0m\] "; ' . '[ -n "$PS1" ] && PS1="\n\[\033[1;32m\][nix-shell:\w]$\[\033[0m\] "; ' .
'unset NIX_ENFORCE_PURITY; ' . 'unset NIX_ENFORCE_PURITY; ' .
'unset NIX_INDENT_MAKE; ' . 'unset NIX_INDENT_MAKE; ' .
'shopt -u nullglob; ' . 'shopt -u nullglob; ' .
'unset TZ; ' . (defined $ENV{'TZ'} ? "export TZ='${ENV{'TZ'}}'; " : '') .
$envCommand); $envCommand);
$ENV{BASH_ENV} = $rcfile; $ENV{BASH_ENV} = $rcfile;
exec($ENV{NIX_BUILD_SHELL} // "bash", "--rcfile", $rcfile); exec($ENV{NIX_BUILD_SHELL} // "bash", "--rcfile", $rcfile);