[Nix-dev] setting up bash/zsh (completion, key bindings, ...), thinking about discussing more changes?

Marc Weber marco-oweber at gmx.de
Fri Sep 20 01:52:10 CEST 2013


I'd like to draw the attention of every nixos user to this change
request:
https://github.com/NixOS/nixos/pull/256

Its about improving zsh support for nixos. This topic popped up multiple
times - and I'd like to ask all of you which limitations you encountered
using the existing setup system for bash/zsh - also because I wrote an
alternative long time ago https://github.com/NixOS/nixos/pull/138
which has been is use by me since then. Its a prototype which means some
implementation details can still be done better.

Rather than voting for my patch I'd like to ask and understand which of
the features I implemented are worth caring about. Let me show you a
simple example how configuration.nix ends up in user's .bashrc:

==================================================
configuration.nix:

  users.defaultUserShell = "/var/run/current-system/sw/bin/zsh";

  # support /etc/zsh,bash/* initialization:
  zsh.enable = true;
  bash.enable = true;

  # very custom code useful to admin and most user accounts he's using,
  # but not all:
  bash.availableFeatures.interacitve.install_vam = ''
    vim-install-vam(){
      # do stuff
    }
  '';

  # provide a load completion implementation allowing to opt-out by file
  # name:
  bash.availableFeatures.interacitve.completion = ''
    nix_add_profile_completion(){
      local profile="$1"

      # origin: bash_completion, slightly adopted
      # source script only once - allow user to use NIX_COMPL_SCRIPT_SOURCED to
      # opt out from bad scripts. If a user wants to reload all he can clear
      # NIX_COMPL_SCRIPT_SOURCED

      local nullglobStatus=$(shopt -p nullglob)
      shopt -s nullglob
      for s in "$profile"/etc/bash_completion.d/* "$p/share/bash-completion/completions/"*; do
        local base="${s/*\//}"
        [[
          -z "${NIX_COMPL_SCRIPT_SOURCED[$base]}" &&
          -z "${NIX_COMPL_SCRIPT_SOURCED[ALL]}"
        ]] && { . "$s"; NIX_COMPL_SCRIPT_SOURCED[$base]=1; }

      done
      eval "$nullglobStatus"
    }
    nix_foreach_profile nix_add_profile_completion

  '';

  bash.availableFeatures.env_code.add_opt_x_to_path = ''
    PATH=$PATH:/opt/x/bin
  '';


==================================================
$HOME/.bashrc:

  # default implementation
  source /etc/bash/setup-all


==================================================
/etc/bash/setup-all:
  source setup # this populates KNOWN_FEATURES, PROFILES, ...

  # non interactive
  setup_path (this is more complicated)
  add_opt_x_to_path

  # interactive:
  activate_features $KNOWN_FEATURES


Now you could copy paste contents from setup-all into your .bashrc and
opt-in/out from indivdiual features easily. That's the main idea and the
main difference to the current master setup.

Is having such features users can opt-in/out only useful to me, or are
more users interested in this?

Please pay attention that the user's .bashrc is not a symlink.
This way he can add his own aliases and still get system updates
from setup-all without having to unlink .bashrc first.

The patch I submitted to nixos shares the principles illustrated here,
but differs in implementation details.

So please let me know whether its time to discuss allowing more control
and how to implement it now because it looks like this topic is hot
right now.

Marc Weber


More information about the nix-dev mailing list