Skip to content

manpages of host OS are not visible for me #432

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

Closed
akavel opened this issue Oct 29, 2018 · 8 comments
Closed

manpages of host OS are not visible for me #432

akavel opened this issue Oct 29, 2018 · 8 comments

Comments

@akavel
Copy link

akavel commented Oct 29, 2018

I cannot seem to be able to access the manpages of my host Ubuntu 16.04 LTS distribution with HM installed, when using the seemingly HM-provided man:

$ man bash
/home/akavel/.nix-profile/bin/man: can't set the locale; make sure $LC_* and $LANG are correct
No manual entry for bash
$ ls -l `which man`
lrwxrwxrwx 1 akavel akavel 69 sty  1  1970 /home/akavel/.nix-profile/bin/man -> /nix/store/1xq6j8hdcpd25zvhmsazfypxy37y8l87-home-manager-path/bin/man
$ /usr/bin/man bash | head -n4
BASH(1)                     General Commands Manual                    BASH(1)

NAME
       bash - GNU Bourne-Again SHell

Actually, there seem to be 3 problems with man; to me they kinda seem to faintly hint at some possible issue with environment variables maybe not being accessible to man (??? or no default values for them? or maybe actually being "set to empty" instead of being "unset"; IIRC, bash differentiates those two states...), but I'm not sure about it. The problems are:

  1. the host manpages are not visible (as shown in the snippet above);
  2. man displays this weird message about locale: can't set the locale; make sure $LC_* and $LANG are correct;
  3. also, if it displays a known page (for a Nix-installed command), it doesn't filter it through less — it just dumps it in entirety, scrolling past to the end; like if it had some problems getting a default value for $PAGER (I have it empty, but the OS man correctly defaults to less; if I do PAGER= /usr/bin/man bash, the host man also dumps everything at once; if I do PAGER=less man home-configuration.nix, the Nix man correctly uses less as pager).

I tried to reduce the home.nix to the smallest example, and it seems to happen to me with the most basic HM config already, as shown below:

$ cat ~/.config/nixpkgs/home.nix
{
  programs.home-manager.enable = true;
  programs.home-manager.path = https://github.com/rycee/home-manager/archive/master.tar.gz;
}

Any hints what could I try to do to improve the situation? Some wrapProgram trickery maybe? Currently, I'm coping with calling /usr/bin/man when I need, and man home-configuration.nix |& less when I need that one, but I'd love to have them integrated in a transparent way :)

Maybe it's a problem in nixpkgs, rather than in HM?

edit: I got a suspicion that it might be Nix's patchelf replacing some default paths in the man binary; it appears to me that this may be a correct suspicion:

$ cat `which man`
#! /nix/store/r47p5pzx52m3n34vdgqpk5rvqgm0m24m-bash-4.4-p23/bin/bash -e
export PATH='/nix/store/snv6vdf3y24wkmjbw7ngb6g9gh5v9m90-groff-1.22.3/bin'${PATH:+':'}$PATH
exec -a "$0" "/nix/store/9vcjavzzhq739mm5g29vm1a2q4zcq2qm-man-db-2.7.5/bin/.man-wrapped"  "${extraFlagsArray[@]}" "$@"
$ strings /nix/store/9vcjavzzhq739mm5g29vm1a2q4zcq2qm-man-db-2.7.5/bin/.man-wrapped | grep man-db
/nix/store/9vcjavzzhq739mm5g29vm1a2q4zcq2qm-man-db-2.7.5/lib/man-db:/nix/store/sh2smlv0b1xg8rggkzz1z14bgwi8dxag-libpipeline-1.5.0/lib:/nix/store/lhrb8mw8c4z0vj43mmglpl9ibb1hkqcb-db-5.3.28/lib:/nix/store/g2yk54hifqlsjiha3szr4q3ccmdzyrdv-glibc-2.27/lib
/nix/store/9vcjavzzhq739mm5g29vm1a2q4zcq2qm-man-db-2.7.5/bin/whatis
/nix/store/9vcjavzzhq739mm5g29vm1a2q4zcq2qm-man-db-2.7.5/bin/apropos
/nix/store/9vcjavzzhq739mm5g29vm1a2q4zcq2qm-man-db-2.7.5/libexec/man-db/zsoelim
/nix/store/9vcjavzzhq739mm5g29vm1a2q4zcq2qm-man-db-2.7.5/libexec/man-db/manconv
/nix/store/9vcjavzzhq739mm5g29vm1a2q4zcq2qm-man-db-2.7.5/etc/man_db.conf
$ strings /usr/bin/man | grep man-db
/usr/lib/man-db
/usr/lib/man-db/zsoelim
/usr/lib/man-db/manconv
$ strings /usr/bin/man | grep conf
config-file
no browser configured, so cannot show HTML output
use this user configuration file
/etc/manpath.config
From the config file %s:
is in the config file
is not in the config file
can't make sense of the manpath configuration file %s
can't open the manpath configuration file %s

edit 2: I compared the host's manpath.config vs. Nix's man_db.conf, and the latter seems to have many paths replaced with /run/current-system/sw/share/man. Do I understand correctly that this is a path that's available only in NixOS? Which would mean that nixpkgs' man seems to have some NixOS-specific tweaks hardcoded?

Click to expand the full diff

--- /etc/manpath.config	2015-11-07 00:14:35.000000000 +0100
+++ /nix/store/9vcjavzzhq739mm5g29vm1a2q4zcq2qm-man-db-2.7.5/etc/man_db.conf	1970-01-01 01:00:01.000000000 +0100
@@ -1,4 +1,4 @@
-# manpath.config
+# man_db.conf
 #
 # This file is used by the man-db package to configure the man and cat paths.
 # It is also used to provide a manpath for those without one by examining
@@ -18,25 +18,25 @@
 #MANDATORY_MANPATH 			/usr/src/pvm3/man
 #
 MANDATORY_MANPATH			/usr/man
-MANDATORY_MANPATH			/usr/share/man
-MANDATORY_MANPATH			/usr/local/share/man
+MANDATORY_MANPATH			/run/current-system/sw/share/man
+MANDATORY_MANPATH			/run/current-system/sw/share/man
 #---------------------------------------------------------
 # set up PATH to MANPATH mapping
 # ie. what man tree holds man pages for what binary directory.
 #
 #		*PATH*        ->	*MANPATH*
 #
-MANPATH_MAP	/bin			/usr/share/man
-MANPATH_MAP	/usr/bin		/usr/share/man
-MANPATH_MAP	/sbin			/usr/share/man
-MANPATH_MAP	/usr/sbin		/usr/share/man
+MANPATH_MAP	/bin			/run/current-system/sw/share/man
+MANPATH_MAP	/usr/bin		/run/current-system/sw/share/man
+MANPATH_MAP	/sbin			/run/current-system/sw/share/man
+MANPATH_MAP	/usr/sbin		/run/current-system/sw/share/man
 MANPATH_MAP	/usr/local/bin		/usr/local/man
-MANPATH_MAP	/usr/local/bin		/usr/local/share/man
+MANPATH_MAP	/usr/local/bin		/run/current-system/sw/share/man
 MANPATH_MAP	/usr/local/sbin		/usr/local/man
-MANPATH_MAP	/usr/local/sbin		/usr/local/share/man
+MANPATH_MAP	/usr/local/sbin		/run/current-system/sw/share/man
 MANPATH_MAP	/usr/X11R6/bin		/usr/X11R6/man
 MANPATH_MAP	/usr/bin/X11		/usr/X11R6/man
-MANPATH_MAP	/usr/games		/usr/share/man
+MANPATH_MAP	/usr/games		/run/current-system/sw/share/man
 MANPATH_MAP	/opt/bin		/opt/man
 MANPATH_MAP	/opt/sbin		/opt/man
 #---------------------------------------------------------
@@ -64,9 +64,9 @@
 #		*MANPATH*     ->	*CATPATH*
 #
 MANDB_MAP	/usr/man		/var/cache/man/fsstnd
-MANDB_MAP	/usr/share/man		/var/cache/man
+MANDB_MAP	/run/current-system/sw/share/man		/var/cache/man
 MANDB_MAP	/usr/local/man		/var/cache/man/oldlocal
-MANDB_MAP	/usr/local/share/man	/var/cache/man/local
+MANDB_MAP	/run/current-system/sw/share/man	/var/cache/man/local
 MANDB_MAP	/usr/X11R6/man		/var/cache/man/X11R6
 MANDB_MAP	/opt/man		/var/cache/man/opt
 #
@@ -75,7 +75,7 @@
 # of the definition is already the default.  To change: uncomment a
 # definition and modify it.
 #
-#DEFINE 	pager	pager
+#DEFINE 	pager	
 #DEFINE 	cat	cat
 #DEFINE 	tr	tr '\255\267\264\327' '\055\157\047\170'
 #DEFINE		grep	grep
@@ -84,10 +84,10 @@
 #DEFINE 	eqn 	eqn
 #DEFINE 	neqn	neqn
 #DEFINE 	tbl 	tbl
-#DEFINE 	col 	col
-#DEFINE 	vgrind 	vgrind
+#DEFINE 	col 	
+#DEFINE 	vgrind 	
 #DEFINE 	refer 	refer
-#DEFINE 	grap 	grap
+#DEFINE 	grap 	
 #DEFINE 	pic 	pic -S
 #
 #DEFINE		compressor	gzip -c7
@@ -108,7 +108,7 @@
 # particular order. Sections with extensions should usually be adjacent to
 # their main section (e.g. "1 1mh 8 ...").
 #
-SECTION		1 n l 8 3 2 3posix 3pm 3perl 5 4 9 6 7
+SECTION		1 n l 8 3 0 2 5 4 9 6 7
 #
 #---------------------------------------------------------
 # Range of terminal widths permitted when displaying cat pages. If the

Though this still doesn't explain the problems with LC_ALL and PAGER to me.

@sboosali
Copy link
Contributor

sboosali commented Oct 30, 2018 via email

@akavel
Copy link
Author

akavel commented Oct 30, 2018

Just noticed that the "LC_ALL" message also gets displayed for me just after I open a new terminal window:

/home/akavel/.nix-profile/bin/manpath: can't set the locale; make sure $LC_* and $LANG are correct

though I'm not sure how this can happen? I don't see any calls that could obviously do that in the script added to my ~/.profile by nix (i.e. /home/akavel/.nix-profile/etc/profile.d/nix.sh).

@rycee
Copy link
Member

rycee commented Oct 30, 2018

Thanks for the very detailed report! I think this is an upstream issue but I'm guessing they would say not to use the man package from Nixpkgs on non-NixOS installs 🙂

So I think you might be best off not using the man module but instead just putting

home.extraOutputsToInstall = [ "man" ];

in your configuration to make sure the man outputs are installed. Using your system man package should be able to view man pages installed through Nixpkgs since ~/.nix-profile/etc/profile.d/nix.sh contains

if [ -n "${MANPATH}" ]; then
    export MANPATH="$NIX_LINK/share/man:$MANPATH"
fi

About PAGER variable I guess the Ubuntu man package will use a default value when it is unset? The Nixpkgs man package doesn't seem to have such a default and instead relies on the default set in the NixOS programs.environment module.

And about the LC_ALL I'm not sure. Maybe you are having a locale that is unsupported by the Nixpkgs man package? And why it would print the error when the shell start I can't imagine. Grepping the Nixpkgs sources I can only imagine it happening if you are using the fish shell. But yeah, you're definitely best off not using the Nixpkgs man package 🙂

@akavel
Copy link
Author

akavel commented Oct 30, 2018

So I should set manual.manpages.enable = false; apart from the extraOutputsToInstall, right? (it seems that when unspecified, it is by default true)

edit: Also, I seem to have empty $MANPATH, so IIUC, the if won't trigger? :)

edit 2: I tried:

    manual.manpages.enable = false;
    home.extraOutputsToInstall = [ "man" ];

but which man still shows the Nix one, and now man home-configuration.nix fails to find it. (Though e.g. man gifsicle still works, for a package installed with nix-env -iA.)

@rycee
Copy link
Member

rycee commented Oct 31, 2018 via email

@akavel
Copy link
Author

akavel commented Oct 31, 2018

Wooohooo, it worked! ❤️

$ cat ~/.nixpkgs/config/home.nix
...
    programs.man.enable = false;
    home.extraOutputsToInstall = [ "man" ];
...
$ home-manager switch
$ man
bash: /home/akavel/.nix-profile/bin/man: No such file or directory
$ hash -d man
$ man
What manual page do you want?
$ man bash
...
$ man home-configuration.nix 
...

Though I don't really understand why it works even for home-configuration.nix :) given that I don't have $MANPATH set... hmm; but maybe some builtin man trickery (akin to the MANPATH_MAN in /etc/manpath.config) auto-translates a ~/.nix-profile/bin in $PATH to ~/.nix-profile/share/man ?

Anyway, HUGE THANKS!!!

And by the way, would you consider somehow making this attribute default to false on non-NixOS host systems? What would you think about this? Could it be possible at all?

@akavel akavel closed this as completed Oct 31, 2018
Zyst added a commit to Zyst/dotfiles that referenced this issue Oct 17, 2019
@mogria
Copy link
Contributor

mogria commented Apr 18, 2020

Mhh I just stumbled upon this, the problem was that the home.language module allows setting all these localization strings, but forgets to set LC_ALL.

LC_ALL=en_US.UTF-8 man <term> worked as a quick fix.

But of course you can just set it in your home.nix config file:

home.sessionVariables = {
  LANG = "en_US.UTF-8";
}

@mogria
Copy link
Contributor

mogria commented Apr 18, 2020

ah that with LC_ALL was correct, LC_ALL exists to overwrite all the other LC_* variables. LANG is the fallback settnig (I assumed it was the other way around ^^).

see man 7 locale for more info (thx to this https://superuser.com/a/392452)

shihanng added a commit to shihanng/dotfiles that referenced this issue May 31, 2020
midchildan added a commit to midchildan/dotfiles that referenced this issue Dec 3, 2020
This module installs manual pages without hiding the operating system's
existing manual pages. I wrote this module because the manual pages for
XCode Command Line Tools on macOS were not showing up with the default
Home Manager configuration. A similar issue was reported at
nix-community/home-manager#432.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants