From 86c643c42760ac55f7be684f6412e364fdf92999 Mon Sep 17 00:00:00 2001 From: sternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org> Date: Fri, 9 Apr 2021 16:38:45 +0200 Subject: [PATCH] nix shell: set MANPATH for installables that have a man dir The major change introduced in this commit is that nix shell will extend MANPATH with the /share/man directory of all installables present in the shell. This means that the support for man pages in nix shell becomes more portable. Currently man pages are discovered by an undocumented (at least not in its man page) feature of man-db's man(1) which also checks PATH to heuristically find prefixes to search for man pages. This is not supported by mandoc's man(1), but MANPATH is supported by both. This allows us to partially revert the changes made in c87f4b9324b87a059cf760a477177f322bb8dc26 as well: Since we don't need to rely on man-db's PATH behavior for discovering man pages, we can only add a bin directory to PATH if it exists. Tested with both mandoc and man-db: * nix shell -f '' mblaze -c man mshow * nix shell -f '' libunwind.devman -c man libunwind --- src/nix/run.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/nix/run.cc b/src/nix/run.cc index b5d8ab38a3f..66c9d5a290a 100644 --- a/src/nix/run.cc +++ b/src/nix/run.cc @@ -104,16 +104,22 @@ struct CmdShell : InstallablesCommand, RunCommon, MixEnvironment setEnviron(); auto unixPath = tokenizeString(getEnv("PATH").value_or(""), ":"); + auto manPath = tokenizeString(getEnv("MANPATH").value_or(""), ":"); while (!todo.empty()) { auto path = todo.front(); todo.pop(); if (!done.insert(path).second) continue; - if (true) - unixPath.push_front(store->printStorePath(path) + "/bin"); + auto pathString = store->printStorePath(path); - auto propPath = store->printStorePath(path) + "/nix-support/propagated-user-env-packages"; + if (accessor->stat(pathString + "/bin").type != FSAccessor::tMissing) + unixPath.push_front(pathString + "/bin"); + + if (accessor->stat(pathString + "/share/man").type != FSAccessor::tMissing) + manPath.push_front(pathString + "/share/man"); + + auto propPath = pathString + "/nix-support/propagated-user-env-packages"; if (accessor->stat(propPath).type == FSAccessor::tRegular) { for (auto & p : tokenizeString(readFile(propPath))) todo.push(store->parseStorePath(p)); @@ -121,6 +127,7 @@ struct CmdShell : InstallablesCommand, RunCommon, MixEnvironment } setenv("PATH", concatStringsSep(":", unixPath).c_str(), 1); + setenv("MANPATH", concatStringsSep(":", manPath).c_str(), 1); Strings args; for (auto & arg : command) args.push_back(arg);