-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nix shell: set MANPATH for installables that have a man dir #4702
base: master
Are you sure you want to change the base?
Conversation
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 c87f4b9 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 '<nixpkgs>' mblaze -c man mshow * nix shell -f '<nixpkgs>' libunwind.devman -c man libunwind
The problem with this is that there are numerous such environment variables (e.g. |
Maybe this is something mkShell or stdenv.mkDerivation should do.
On April 15, 2021, GitHub ***@***.***> wrote:
The problem with this is that there are numerous such environment
variables (e.g. XDG_DATA_DIRS, PYTHONPATH, PKG_CONFIG_PATH) and it
wouldn't be very elegant to add ad hoc support for each of them to nix
shell.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#4702 (comment)>, or
unsubscribe <https://github.com/notifications/unsubscribe-
auth/AAASXLGCRY7KY5CQBTOIJITTI3JEDANCNFSM42VHFLVA>.
|
From what I understand I think setting up
That would work for the old |
The problem is that we haven't really decided what the semantics or use case of
This is already a pretty open-ended set of environment variables, especially if you consider packages that provide plugins. E.g. should |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
I marked this as stale due to inactivity. → More info |
bump |
@thufschmitt can you help to bring this forward? |
I enqueued it on project board. |
Triaged in Nix maintainers meeting:
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-06-30-nix-team-meeting-minutes-67/29835/1 |
If you are taking that stance, I think I am actually very open to explore this hardline view, as I believe it would hold the key to solve one problem we have, namely the dubious status of (development) environments. We currently inherit development environments from derivations' build environments which is arguably wrong. The symptoms of this are the variety of
I feel like the solution may be to have a second type of special Nix value in addition to derivation that does not declare a build environment and instructions, but an environment modification (how to encode that is another question, you could probably look to In any case, if we are serious about “delegating authority away from Nix”, a lot of things need to be re-evaluated. By the same logic, it feels questionable that the following things are Nix commands:
|
To be even more provocative: Shouldn't shells, any kind of environments just be |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/nixpkgs-cli-working-group/30517/1 |
Discussed during the Nix team meeting: @sternenseemann since you're already climbing down that rabbit hole, would you be willing to write down in more detail / discuss the idea of splitting away Discussion log
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-07-24-nix-team-meeting-minutes-74/31116/1 |
I tried rebasing this PR on nix 2.19 and tested it successful with the example commands from above. diff --git a/src/nix/run.cc b/src/nix/run.cc
index ea0a17897..5491f4a7b 100644
--- a/src/nix/run.cc
+++ b/src/nix/run.cc
@@ -111,16 +111,22 @@ struct CmdShell : InstallablesCommand, MixEnvironment
setEnviron();
auto unixPath = tokenizeString<Strings>(getEnv("PATH").value_or(""), ":");
+ auto manPath = tokenizeString<Strings>(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 = CanonPath(store->printStorePath(path)) + "nix-support" + "propagated-user-env-packages";
+ if (accessor->maybeLstat(CanonPath(pathString) + "bin"))
+ unixPath.push_front(pathString + "/bin");
+
+ if (accessor->maybeLstat(CanonPath(pathString) + "share" + "man"))
+ manPath.push_front(pathString + "/share/man");
+
+ auto propPath = CanonPath(pathString) + "nix-support" + "propagated-user-env-packages";
if (auto st = accessor->maybeLstat(propPath); st && st->type == SourceAccessor::tRegular) {
for (auto & p : tokenizeString<Paths>(accessor->readFile(propPath)))
todo.push(store->parseStorePath(p));
@@ -128,6 +134,7 @@ struct CmdShell : InstallablesCommand, 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); |
A few spontaneous ideas:
Bonus points for separation of concerns if the all of the command line business that's not |
@fricklerhandwerk your second proposal seems to be more or less #7501, which everyone seems to broadly agree with. So 💯 to it. |
My ramblings #4702 (comment) were missing the fact that only It's not clear how one would compose an environment from entire shell runs in a simple and obvious way. In any case it would need some sort of contract to implement against, and I'd prefer it to be very small, both in terms of API surface as well as amount of custom code needed to implement it.
In short, I suggest to leave |
@fricklerhandwerk Should we draft an RFC to see what can be developed from this idea and what's the attitude of the community? |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
I agree with the general architectural idea, but I would hate to see some of these very useful commands go. I use The main challenge I see is to provide an easy way to add functionality to one's installation. There must be some sort of canonical default entrypoint to start from. I concur that Nix shouldn't
so this default should be declarative and work exactly like composition works everywhere else in Nix, so no Maybe the solution can simply be to source Nix differently. In addition to adding
to source "$(nix build --no-link --print-out-paths path:$HOME/.config/nix/user#userEnv)"
# OR
source "$(nix build --no-link --print-out-paths --file $HOME/.config/nix/userEnv.nix)" after or during the shell startup by default. This would replace If we find a good mechanism for this entrypoint, I believe this architectural change would solve all the issues that motivate it without negatively impacting the user experience at all. (We still might need |
My general idea on this is to essentially port all the porcelain into Nixpkgs and, from there, provide installers for various targets that embed Nix. Then you'd install a Nixpkgs release rather than a Nix release which implicitly sets you up with some Nixpkgs. That could also solve the compatibility struggles between Nix and Nixpkgs to some degree. But I haven't put much thought into how exactly all of that would work. (Another potentially beneficial side effect of doing it that way would be that we could then formally eject the installation business from the Nix code base and let distributors take care of that, according to their needs. Then all we'd have to do is provide documentation on the moving parts that need to be considered. My impression is that the Nixpkgs community would be much more capable of carrying that load than Nix maintainers are at the moment.) Edit: @Aleksanaa I don't think this needs an RFC, but a prototype to get an idea of how it feels to work with it and how much effort it is to maintain and evolve. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
I gave the whole thing another series of thoughts, and studied the
That way we could produce arbitrary shells from Nixpkgs packages. One could also reproduce build environments based on NixOS/nixpkgs#324789. Maybe with some trickery we could build a wrapper that takes some information from a failed build and starts the shell in the temporary build directory. Most of the complexity of What do you think? |
The major change introduced in this commit is that nix shell will extend
MANPATH
with the/share/man
directory of all installables present in theshell. 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 alsochecks
PATH
to heuristically find prefixes to search for man pages.This is not supported by mandoc's
man(1)
, butMANPATH
is supported byboth.
This allows us to partially revert the changes made in
c87f4b9 as well: Since we don't need to
rely on man-db's
PATH
behavior for discovering man pages, we can onlyadd a
bin
directory toPATH
if it exists.Tested with both mandoc and man-db:
nix shell -f '<nixpkgs>' mblaze -c man mshow
nix shell -f '<nixpkgs>' libunwind.devman -c man libunwind