nix develop: Filter some bash magic variables

This commit is contained in:
Eelco Dolstra 2021-07-09 01:02:47 +02:00
parent b1f1347ade
commit 5f6375a816
2 changed files with 15 additions and 5 deletions

View file

@ -72,7 +72,7 @@ struct BuildEnvironment
void toBash(std::ostream & out, const std::set<std::string> & ignoreVars) const void toBash(std::ostream & out, const std::set<std::string> & ignoreVars) const
{ {
for (auto & [name, value] : vars) { for (auto & [name, value] : vars) {
if (!ignoreVars.count(name) && !hasPrefix(name, "BASH_")) { if (!ignoreVars.count(name)) {
if (auto str = std::get_if<String>(&value)) { if (auto str = std::get_if<String>(&value)) {
out << fmt("%s=%s\n", name, shellEscape(str->value)); out << fmt("%s=%s\n", name, shellEscape(str->value));
if (str->exported) if (str->exported)
@ -191,17 +191,13 @@ struct Common : InstallableCommand, MixProfile
{ {
std::set<std::string> ignoreVars{ std::set<std::string> ignoreVars{
"BASHOPTS", "BASHOPTS",
"EUID",
"HOME", // FIXME: don't ignore in pure mode? "HOME", // FIXME: don't ignore in pure mode?
"HOSTNAME",
"NIX_BUILD_TOP", "NIX_BUILD_TOP",
"NIX_ENFORCE_PURITY", "NIX_ENFORCE_PURITY",
"NIX_LOG_FD", "NIX_LOG_FD",
"NIX_REMOTE", "NIX_REMOTE",
"PPID", "PPID",
"PWD",
"SHELLOPTS", "SHELLOPTS",
"SHLVL",
"SSL_CERT_FILE", // FIXME: only want to ignore /no-cert-file.crt "SSL_CERT_FILE", // FIXME: only want to ignore /no-cert-file.crt
"TEMP", "TEMP",
"TEMPDIR", "TEMPDIR",

View file

@ -42,6 +42,20 @@ __dumpEnv() {
local type="${BASH_REMATCH[1]}" local type="${BASH_REMATCH[1]}"
local __var_name="${BASH_REMATCH[2]}" local __var_name="${BASH_REMATCH[2]}"
if [[ $__var_name =~ ^BASH_ || \
$__var_name = _ || \
$__var_name = DIRSTACK || \
$__var_name = EUID || \
$__var_name = FUNCNAME || \
$__var_name = HISTCMD || \
$__var_name = HOSTNAME || \
$__var_name = PIPESTATUS || \
$__var_name = PWD || \
$__var_name = RANDOM || \
$__var_name = SHLVL || \
$__var_name = SECONDS \
]]; then continue; fi
if [[ -z $__first ]]; then printf ',\n'; else __first=; fi if [[ -z $__first ]]; then printf ',\n'; else __first=; fi
printf " " printf " "