[Nix-dev] Garbled man pages/incomplete environment
Jeffrey David Johnson
jefdaj at gmail.com
Sun Jul 5 20:59:29 CEST 2015
If I do that it complains that NIX_PATH is set elsewhere already. I
think it's merging the attribute sets but not individual attributes.
Which is good, wouldn't want it just concatenating strings or something
else magical. That's why I originally put in the lib.mkForce to
override it.
Thanks for mentioning it though, because that led me to figure it out! I
found the function that does the merging in
nixpkgs/nixos/modules/config/shells-environment.nix:
environment.variables = mkOption {
default = {};
description = ''
A set of environment variables used in the global environment.
These variables will be set on shell initialisation.
The value of each variable can be either a string or a list of
strings. The latter is concatenated, interspersed with colon
characters.
'';
type = types.attrsOf (mkOptionType {
name = "a string or a list of strings";
merge = loc: defs:
let
defs' = filterOverrides defs;
res = (head defs').value;
in
if isList res then concatLists (getValues defs')
else if lessThan 1 (length defs') then
throw "The option `${showOption loc}' is defined multiple
times, in ${showFiles (getFiles defs)}." else if !isString res then
throw "The option `${showOption loc}' does not have a
string value, in ${showFiles (getFiles defs)}." else res;
});
apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v
else v); };
The mkOverrides looked related, so I found it in
nixpkgs/lib/modules.nix. It's a little over my head but the comments
explain:
/* Given a list of config values, process the mkOverride properties,
that is, return the values that have the highest (that is,
numerically lowest) priority, and strip the mkOverride
properties. For example,
[ { file = "/1"; value = mkOverride 10 "a"; }
{ file = "/2"; value = mkOverride 20 "b"; }
{ file = "/3"; value = "z"; }
{ file = "/4"; value = mkOverride 10 "d"; }
]
yields
[ { file = "/1"; value = "a"; }
{ file = "/4"; value = "d"; }
]
Note that "z" has the default priority 100.
*/
So I used that, and it works!
environment.variables = rec {
# other vars here
NIX_PATH = lib.mkOverride 10 "/git/hub/nixcfg"; # use anything below 100
};
I think I even about that in the manual somewhere, but had forgotten it.
Jeff
On Sun, 5 Jul 2015 11:17:10 -0700
James Cook <james.cook at utoronto.ca> wrote:
> What if you leave out the "config.environment.variables //" part (just
> environment.variables = { NIX_PATH = "/git/hub/nixcfg"; };)?
>
> The NixOS config infrastructure is supposed to take care of the //
> part for you. I think the infinite recursion happens because
> config.environment.variables is partly based on the value you define
> for environment.variables.
>
> James
>
> On 5 July 2015 at 10:51, Jeffrey David Johnson <jefdaj at gmail.com> wrote:
> > Thanks, you're right that was it! I put the mkForce in while trying to
> > set NIX_PATH, then forgot to remove it after moving that to
> > interactiveShellInit instead. Man pages/environment variables back to
> > normal.
> >
> > That reminds me though, is there a way to force NIX_PATH while leaving
> > the rest in place? I tried:
> >
> > { config, ... }:
> > { environment.variables = config.environment.variables // {
> > # my other vars here
> > NIX_PATH = "/git/hub/nixcfg";
> > };
> > }
> >
> > But it causes infinite recursion. I imagine there's a special hook
> > or override pattern for that?
> > Jeff
> >
> > On Sat, 4 Jul 2015 18:20:20 -0700
> > James Cook <james.cook at utoronto.ca> wrote:
> >
> >> On 4 July 2015 at 09:24, Jeffrey David Johnson <jefdaj at gmail.com> wrote:
> >> > I'm having the same issue described here on the Gentoo forums:
> >> >
> >> > https://forums.gentoo.org/viewtopic-t-670013.html
> >> >
> >> > Man pages are hard to read because they're full of control characters. For example:
> >> >
> >> > NIXOS-REBUILD(8) NixOS Reference Pages NIXOS-REBUILD(8)
> >> >
> >> > ESC[1mNAMEESC[0m
> >> > nixos-rebuild - reconfigure a NixOS machine
> >> >
> >> > ESC[1mSYNOPSISESC[0m
> >> > ESC[1mnixos-rebuild ESC[22m{ESC[1mswitch ESC[22m| ESC[1mboot ESC[22m| ESC[1mtest
> >> > ESC[22m| ESC[1mbuild ESC[22m| ESC[1mdry-build ESC[22m| ESC[1mdry-activate ESC[22m|
> >> > ...
> >> >
> >> > I expect it's a problem with my environment variables, so
> >> > here's my profile.nix which I import into configuration.nix:
> >> >
> >> > with import <mypkgs>;
> >> >
> >> > {
> >> > programs.bash = {
> >> > enableCompletion = true;
> >> > # promptInit = "PS1=\"# \"";
> >> > };
> >> >
> >> > # replaces traditional xinitrc
> >> > services.xserver.displayManager.sessionCommands = ''
> >> > export EDITOR=qvim # why no gvim?
> >> > xsetroot -cursor_name left_ptr &
> >> > [[ -a ~/.fehbg ]] && eval $(cat ~/.fehbg)
> >> > unclutter -idle 1 &
> >> > eval "$(ssh-agent -s)" &
> >> > '';
> >> >
> >> > environment.variables = lib.mkForce rec {
> >> > EDITOR = "vim" ;
> >> > TERM = TERMINAL;
> >> > TERMINAL = "xfce4-terminal";
> >> > };
> >> >
> >> > # this gets reset if in environment.variables for some reason
> >> > environment.interactiveShellInit = ''
> >> > export NIX_PATH=/git/hub/nixcfg
> >> > '';
> >> >
> >> > # TODO why can't nix-env find things on the regular NIX_PATH?
> >> > environment.shellAliases = {
> >> > "nix-env" = "nix-env -f ${<mypkgs>}";
> >> > };
> >> > }
> >> >
> >> > As you can see I also have issues setting up NIX_PATH.
> >> > The current kludgy solution is working OK, but if you know
> >> > how to clean it up please mention that too! My worry is
> >> > that I've deleted all the environment variables not
> >> > mentioned here including some important ones, and man
> >> > pages are just the first thing I noticed.
> >> >
> >> > Thanks
> >> > Jeff
> >>
> >> The only thing that comes to mind: environment.varibles = lib.mkForce
> >> ... looks suspicious to me. Does it work without the mkForce?
> >>
> >> (If environment.variables is like other configuration variables I've
> >> met, then mkForce means discard whatever the defaults are, and leaving
> >> out mkForce means append the values you specify to whatever the
> >> defaults are.)
> >>
> >> You could always start commenting out parts of the configuration and
> >> observing the changes, but of course that's tedious. Maybe using
> >> nixos-rebuild build-vm could help.
> >>
> >> James
> > _______________________________________________
> > nix-dev mailing list
> > nix-dev at lists.science.uu.nl
> > http://lists.science.uu.nl/mailman/listinfo/nix-dev
More information about the nix-dev
mailing list