[Nix-dev] Re: zsh in NixOS

Karn Kallio tierpluspluslists at gmail.com
Fri Oct 1 01:38:52 CEST 2010


> I was trying to help Twey set up zsh as his shell.
> 
> I first suggested that he set users.defaultUserShell to something like
> "${pkgs.zsh}/bin/zsh"; however the NixOS manual says:
> 
> ``¡This must not be a store path, since the path is used outside the store
> (in particular in /etc/passwd).  Rather, it should be the path of a
> symlink that points to the actual shell in the Nix store.¢
> 
> I'm not exactly sure why the restriction, but anyhow.
> 

It occurs to me that using store paths in files like /etc/passwd means that 
you are vulnerable to garbage collection in the store.  The store garbage 
collector does not know that /etc/passwd holds a reference to a store object.  
Also external store paths must be updated "by hand" whenever you upgrade some 
packages.

> I next suggested setting
> 
> environment.systemPackages = [ pkgs.zsh ]
> users.defaultUserShell = "/var/run/current-system/sw/bin/zsh"
> 
> This kinda works, but the problem is that /etc/bashrc is sourced, and,
> perhaps not surprisingly, this file doesn't work properly when run in zsh.
> 
> Twey gets the error mentioned at
> <http://www.mail-archive.com/nix-dev@cs.uu.nl/msg02079.html>
> pluse some other problems with for loops.
> 
> I figure there are two approaches to solving this problem.  Either
> /etc/bashrc needs to be run by bash to set the enviroment variables of
> zsh.  I don't know much about shells, but I was told that this isn't
> possible.  Perhaps what needs to be done is to run /etc/bashrc and have it
> do it's thing (e.g. make ~/.nix-profile directories and whatnot) but
> rather than setting environment variables, it outputs the environment
> variables that need to be set.
> 
> The other approach would be to somehow make the work done in /etc/bashrc
> more portable, at least across the bash,zsh,ksh,sh family.
> 
> I'm far from a shell expert, so someone more knowledgeable probably
> wants to ring in here.

I think that in general each shell will need its own rc file, especially if 
NixOs should support shells like scsh (Scheme shell) or es shell ( Plan 9 rc-
alike ) that may be quite different from the sh family.  These various rc 
files could obtain a list of needed environment variables from a common data 
file.  So NixOs could provide /etc/user-environment or something with the list 
of needed environment variables and their values, which each shell would 
process in its own way, and then perform shell-specific configuration 
(prompts, colors, ... ).

However, I am certainly not a shell expert either!



More information about the nix-dev mailing list