aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-07-09 01:02:47 +0200
committerEelco Dolstra <edolstra@gmail.com>2021-07-09 01:18:44 +0200
commit5f6375a816803d17c8ec0f7c2ef960c848be6166 (patch)
treeb601d8b7a7d6e318336f2b34308b5dd8bade1974
parentb1f1347ade81d1f04f2d490baceefb3c4de0b4e3 (diff)
nix develop: Filter some bash magic variables
-rw-r--r--src/nix/develop.cc6
-rw-r--r--src/nix/get-env.sh14
2 files changed, 15 insertions, 5 deletions
diff --git a/src/nix/develop.cc b/src/nix/develop.cc
index e00f0d575..9b2945ba3 100644
--- a/src/nix/develop.cc
+++ b/src/nix/develop.cc
@@ -72,7 +72,7 @@ struct BuildEnvironment
void toBash(std::ostream & out, const std::set<std::string> & ignoreVars) const
{
for (auto & [name, value] : vars) {
- if (!ignoreVars.count(name) && !hasPrefix(name, "BASH_")) {
+ if (!ignoreVars.count(name)) {
if (auto str = std::get_if<String>(&value)) {
out << fmt("%s=%s\n", name, shellEscape(str->value));
if (str->exported)
@@ -191,17 +191,13 @@ struct Common : InstallableCommand, MixProfile
{
std::set<std::string> ignoreVars{
"BASHOPTS",
- "EUID",
"HOME", // FIXME: don't ignore in pure mode?
- "HOSTNAME",
"NIX_BUILD_TOP",
"NIX_ENFORCE_PURITY",
"NIX_LOG_FD",
"NIX_REMOTE",
"PPID",
- "PWD",
"SHELLOPTS",
- "SHLVL",
"SSL_CERT_FILE", // FIXME: only want to ignore /no-cert-file.crt
"TEMP",
"TEMPDIR",
diff --git a/src/nix/get-env.sh b/src/nix/get-env.sh
index 834b84e35..20937b956 100644
--- a/src/nix/get-env.sh
+++ b/src/nix/get-env.sh
@@ -42,6 +42,20 @@ __dumpEnv() {
local type="${BASH_REMATCH[1]}"
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
printf " "