diff options
author | matthew <matthewkenigsberg@gmail.com> | 2019-11-07 17:18:31 -0600 |
---|---|---|
committer | matthew <matthewkenigsberg@gmail.com> | 2019-11-07 17:22:16 -0600 |
commit | 6419f5028b30e8e43222d71d9fd45fd674eed1b7 (patch) | |
tree | 84c4c9f5dc1db84c45baba8ca7d6830728e8b6da /src/nix | |
parent | 75c897cf3d2be5cc156a87ec54c6726e8dc2a926 (diff) |
use MixEnvironment in run and shell
Diffstat (limited to 'src/nix')
-rw-r--r-- | src/nix/run.cc | 51 | ||||
-rw-r--r-- | src/nix/shell.cc | 4 |
2 files changed, 5 insertions, 50 deletions
diff --git a/src/nix/run.cc b/src/nix/run.cc index d65a642c2..0fbd0b8a8 100644 --- a/src/nix/run.cc +++ b/src/nix/run.cc @@ -57,12 +57,9 @@ struct RunCommon : virtual Command } }; -struct CmdRun : InstallablesCommand, RunCommon +struct CmdRun : InstallablesCommand, RunCommon, MixEnvironment { std::vector<std::string> command = { "bash" }; - StringSet keep, unset; - Strings stringEnv; - bool ignoreEnvironment = false; CmdRun() { @@ -76,28 +73,6 @@ struct CmdRun : InstallablesCommand, RunCommon if (ss.empty()) throw UsageError("--command requires at least one argument"); command = ss; }); - - mkFlag() - .longName("ignore-environment") - .shortName('i') - .description("clear the entire environment (except those specified with --keep)") - .set(&ignoreEnvironment, true); - - mkFlag() - .longName("keep") - .shortName('k') - .description("keep specified environment variable") - .arity(1) - .labels({"name"}) - .handler([&](std::vector<std::string> ss) { keep.insert(ss.front()); }); - - mkFlag() - .longName("unset") - .shortName('u') - .description("unset specified environment variable") - .arity(1) - .labels({"name"}) - .handler([&](std::vector<std::string> ss) { unset.insert(ss.front()); }); } std::string description() override @@ -127,28 +102,6 @@ struct CmdRun : InstallablesCommand, RunCommon }; } - void setNewEnviron() { - if (ignoreEnvironment) { - - if (!unset.empty()) - throw UsageError("--unset does not make sense with --ignore-environment"); - - for (const auto & var : keep) { - auto val = getenv(var.c_str()); - if (val) stringEnv.emplace_back(fmt("%s=%s", var.c_str(), val)); - } - - environ = stringsToCharPtrs(stringEnv).data(); - - } else { - if (!keep.empty()) - throw UsageError("--keep does not make sense without --ignore-environment"); - - for (const auto & var : unset) - unsetenv(var.c_str()); - } - } - void run(ref<Store> store) override { auto outPaths = toStorePaths(store, Build, installables); @@ -160,7 +113,7 @@ struct CmdRun : InstallablesCommand, RunCommon std::queue<Path> todo; for (auto & path : outPaths) todo.push(path); - setNewEnviron(); + setEnviron(); auto unixPath = tokenizeString<Strings>(getEnv("PATH"), ":"); diff --git a/src/nix/shell.cc b/src/nix/shell.cc index 50d0f9c88..5e13604bc 100644 --- a/src/nix/shell.cc +++ b/src/nix/shell.cc @@ -229,7 +229,7 @@ struct Common : InstallableCommand, MixProfile } }; -struct CmdDevShell : Common +struct CmdDevShell : Common, MixEnvironment { std::string description() override { @@ -275,6 +275,8 @@ struct CmdDevShell : Common auto shell = getEnv("SHELL", "bash"); + setEnviron(); + auto args = Strings{baseNameOf(shell), "--rcfile", rcFilePath}; restoreAffinity(); |