From c87f4b9324b87a059cf760a477177f322bb8dc26 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 9 Aug 2018 13:01:03 +0200 Subject: nix run: Respect propagated-user-env-packages Also, add $path/bin to $PATH even if it doesn't exist. This makes 'man' work properly (since it looks for ../share/man relative to $PATH entries). --- src/nix/run.cc | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/nix/run.cc b/src/nix/run.cc index d04e106e0..65ced3475 100644 --- a/src/nix/run.cc +++ b/src/nix/run.cc @@ -12,6 +12,8 @@ #include #endif +#include + using namespace nix; std::string chrootHelperName = "__run_in_chroot"; @@ -121,10 +123,27 @@ struct CmdRun : InstallablesCommand unsetenv(var.c_str()); } + std::unordered_set done; + std::queue todo; + for (auto & path : outPaths) todo.push(path); + auto unixPath = tokenizeString(getEnv("PATH"), ":"); - for (auto & path : outPaths) - if (accessor->stat(path + "/bin").type != FSAccessor::tMissing) + + while (!todo.empty()) { + Path path = todo.front(); + todo.pop(); + if (!done.insert(path).second) continue; + + if (true) unixPath.push_front(path + "/bin"); + + auto propPath = path + "/nix-support/propagated-user-env-packages"; + if (accessor->stat(propPath).type == FSAccessor::tRegular) { + for (auto & p : tokenizeString(readFile(propPath))) + todo.push(p); + } + } + setenv("PATH", concatStringsSep(":", unixPath).c_str(), 1); std::string cmd = *command.begin(); -- cgit v1.2.3