From 180984178dc4e063607f6e9e94eb2fdfedbfe452 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Mon, 4 Mar 2024 07:50:55 +0100 Subject: Merge pull request #9648 from cole-h/nix-shell-ordering nix shell: reflect command line order in PATH order (cherry picked from commit b91c935c2faf08ced2c763dcd2a831f26d84fa86) Change-Id: If16c120bb74857c2817366e74e5b0877eb997260 --- src/nix/run.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/nix/run.cc') diff --git a/src/nix/run.cc b/src/nix/run.cc index 1c16ce2c9..94d492ca7 100644 --- a/src/nix/run.cc +++ b/src/nix/run.cc @@ -113,7 +113,7 @@ struct CmdShell : InstallablesCommand, MixEnvironment setEnviron(); - auto unixPath = tokenizeString(getEnv("PATH").value_or(""), ":"); + std::vector pathAdditions; while (!todo.empty()) { auto path = todo.front(); @@ -121,7 +121,7 @@ struct CmdShell : InstallablesCommand, MixEnvironment if (!done.insert(path).second) continue; if (true) - unixPath.push_front(store->printStorePath(path) + "/bin"); + pathAdditions.push_back(store->printStorePath(path) + "/bin"); auto propPath = store->printStorePath(path) + "/nix-support/propagated-user-env-packages"; if (accessor->stat(propPath).type == FSAccessor::tRegular) { @@ -130,7 +130,10 @@ struct CmdShell : InstallablesCommand, MixEnvironment } } - setenv("PATH", concatStringsSep(":", unixPath).c_str(), 1); + auto unixPath = tokenizeString(getEnv("PATH").value_or(""), ":"); + unixPath.insert(unixPath.begin(), pathAdditions.begin(), pathAdditions.end()); + auto unixPathString = concatStringsSep(":", unixPath); + setenv("PATH", unixPathString.c_str(), 1); Strings args; for (auto & arg : command) args.push_back(arg); -- cgit v1.2.3