[Nix-dev] 3nd revision of multi-shell support patch

Marc Weber marco-oweber at gmx.de
Wed Feb 9 10:15:58 CET 2011


The design is pretty final and works fine.
Do you like it?
It also fixes the PATH gets reset issue which I talked about in the previous
thread.

Commit message (summary):

    nixos multi shell support and some improvements (maybe even fixes):
    
    Setup nix related vars always but only once. If NIX_DID_SHELL_INIT is
    set env vars won't be changed when running a subshell by typing zsh,bash
    
    Thus if you modify PATH modification will be kept unless you start a
    login (bash/zsh) shell. This seems to be the default on other systems.
    
    bash specific changes:
    ======================
    
      bash has the behaviour of either sourcing /etc/profile or /etc/bashrc.
      However you want PATH to be set in both cases
      - non login case: scp connects and wants to start scp
      - login case: you connect using ssh
      Thus /etc/profile and /etc/bashrc have almost the same contents.
      The profile script also setups the nix acount.
      The code doing so was put into a script so that it can be reused by zsh
      implementation
    
      The same applies for ~/.profile (or ~/.bash_profile) and ~/.bashrc.
      So to prevent duplication the default skeleton files ~/.bash_profile
      and ~/.bashrc now source a common ~/.bash_setup file which is non
      standard - but is what I think most users want.
      The default is to source /etc/bash-user-system-default.sh which sets
      up completion - without the annoying scripts. Eg upstart and git are
      supported. The user can opt-out from individual scripts by using a
      bash hash - or by simple dropping the line sourcing the script in
      ~/.bash_setup
    
    zsh specific changes:
    =====================
      setup looks similar - but contrast to bash the /etc and ~ .zshrc files
      are always sourced - thus the same setup is simpler and requires less
      files.
    
    The /etc/{zsh,bash}-user-system-defaults.{sh,zsh} files now contain a
    section which can be configured by configuration.nix which is only run
    in interactive shells. This is the place to define EDITOR env vars,
    aliases for ls etc.
    
    Unfortunately zsh and bash (and the other shells which somebody may want
    to support in the future) have much but not enough in common. Thus a lot
    of duplication has to take place - even in .nix files.
    
    In order to make this as convenient as possible a mergeShellCodeOption
    has been introduced in nixpkgs which allows you to write shell code in
    configuration files like this:
    
      environment.interactiveShellInit = [
        ''
        # common code
        ''
        {
          bash = " for x in $VAR; do ...     ";
          zsh  = " for x in ${=VAR}; do ...  ";
        }
        ''
        # more common code
        ''
      ];
    
    and the zsh / bash parts will be picked up accordingly - if attr name is
    missing you should get a nice error message.
    
    A new option type shellcode has been added to options.nix. Because the
    default setting gets not merged it was necessary to use the apply
    function which can now be used in option types as well.
    
    Because I expect that most users use bash zsh is optional. Enable zsh
    support by
    
        environment.supportedShells = [ "bash" "zsh" ];
    
    I'm not sure whether this is the perfect solution - but at least a small
    step ..
    
    I'm also pretty sure that I've missed some details. It should be easy to
    fix them. Enjoy!


Marc Weber
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nixpkgs-lib-shellcode-option.patch
Type: application/octet-stream
Size: 3902 bytes
Desc: not available
Url : http://lists.science.uu.nl/pipermail/nix-dev/attachments/20110209/f7dc75e9/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: multi-shell-support-rev2.patch
Type: application/octet-stream
Size: 34783 bytes
Desc: not available
Url : http://lists.science.uu.nl/pipermail/nix-dev/attachments/20110209/f7dc75e9/attachment-0001.obj 


More information about the nix-dev mailing list