Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/nix/env.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <queue>

#include <boost/unordered/unordered_flat_set.hpp>
#include <boost/algorithm/string/join.hpp>

#include "nix/cmd/command.hh"
#include "nix/expr/eval.hh"
Expand Down Expand Up @@ -78,9 +79,8 @@ struct CmdShell : InstallablesCommand, MixEnvironment
for (auto & path : outPaths)
todo.push(path);

setEnviron();

std::vector<std::string> pathAdditions;
std::vector<std::string> packageNames;

while (!todo.empty()) {
auto path = todo.front();
Expand All @@ -100,8 +100,17 @@ struct CmdShell : InstallablesCommand, MixEnvironment
for (auto & p : tokenizeString<Paths>(state->storeFS->readFile(propPath)))
todo.push(store->parseStorePath(p));
}

packageNames.push_back(std::string(path.name()));
}

auto existingPackagesVar = getEnvOs(OS_STR("NIX_SHELL_PACKAGES")).value_or(OS_STR(""));
if (!existingPackagesVar.empty())
packageNames.push_back(existingPackagesVar);
setVars["NIX_SHELL_PACKAGES"] = boost::algorithm::join(packageNames, " ");

setEnviron();

// TODO: split losslessly; empty means .
auto unixPath = ExecutablePath::load();
unixPath.directories.insert(unixPath.directories.begin(), pathAdditions.begin(), pathAdditions.end());
Expand Down
1 change: 1 addition & 0 deletions tests/functional/shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ sed -i \
-e '/^TMPDIR=\/var\/folders\/.*/d' \
-e '/^__CF_USER_TEXT_ENCODING=.*$/d' \
-e '/^__LLVM_PROFILE_RT_INIT_ONCE=.*$/d' \
-e '/^NIX_SHELL_PACKAGES=.*$/d' \
"$TEST_ROOT/expected-env" "$TEST_ROOT/actual-env"
sort "$TEST_ROOT/expected-env" > "$TEST_ROOT/expected-env.sorted"
sort "$TEST_ROOT/actual-env" > "$TEST_ROOT/actual-env.sorted"
Expand Down
Loading