Skip to content

environment fixes in run - #3191

Merged
edolstra merged 5 commits into
NixOS:flakesfrom
mkenigs:run-environment
Dec 2, 2019
Merged

edolstra merged 5 commits into
NixOS:flakesfrom
mkenigs:run-environment

Conversation

@mkenigs

@mkenigs mkenigs commented Nov 1, 2019

Copy link
Copy Markdown
Contributor

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

edolstra commented Nov 5, 2019

Copy link
Copy Markdown
Member

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

mkenigs commented Nov 7, 2019

Copy link
Copy Markdown
Contributor Author

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

Comment thread src/nix/command.cc Outdated

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
Copy Markdown
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

edolstra commented Dec 2, 2019

Copy link
Copy Markdown
Member

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