Skip to content

Conversation

@mkenigs
Copy link
Contributor

@mkenigs mkenigs commented Nov 1, 2019

Code in #3172 which adds --ignore-environment to dev-shell is redundant because --ignore-environment is already implemented for run. I moved the related code in run to a separate function. If doing it this way works, I was thinking I could move it to a common class that both run and dev-shell can inherit from.

I also changed the way ignore environment is handled, creating a new char* array if ignoreEnvironment is set rather than calling clearEnv. The previous way of doing it had to getenv, clearenv, and setenv for every kept variable, and clearenv for all variables, so it seems like creating a new array might be a better way of doing it that just does one getenv for kept variables. Not sure if it makes the call to runProgram and handling of PATH too complicated.

@edolstra
Copy link
Member

edolstra commented Nov 5, 2019

Maybe we can factor out the environment handling in nix run into a MIxEnvironment class that could be used by nix dev-shell? That way the latter would also get the --keep and --unset flags.

Move environment related code to a separate function. Create a new char** if ignoreEnvironment is set rather than calling clearEnv
@mkenigs
Copy link
Contributor Author

mkenigs commented Nov 7, 2019

Factored code out into MixEnvironment and used it in both run and dev-shell. Changes would close #3172 and #2813


for (const auto & var : keep) {
auto val = getenv(var.c_str());
if (val) stringEnv.emplace_back(fmt("%s=%s", var.c_str(), val));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't compile since stringEnv doesn't exist.

@edolstra edolstra merged commit 062012e into NixOS:flakes Dec 2, 2019
@edolstra
Copy link
Member

edolstra commented Dec 2, 2019

Thanks, merged!

@mkenigs mkenigs deleted the run-environment branch February 12, 2020 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants