Using ZSH with grml config, and nix-shell prompt indicator

I use the GRML zshrc for more than 10 years, and still find it better than the oh-my-zsh prompts especially regarding version control integration (e.g. it shows cleanly whether you are in a git rebase or git cherry-pick).

Here’s how I use it on NixOS, based on my previous post on reddit (which I cannot update any more because Reddit crappily forbids that).

It explains some pitfalls I encountered, and also features showing (nix-shell) in the prompt when I’m in nix-shell.

    # zsh
    programs.zsh.enable = true;
    programs.zsh.interactiveShellInit = ''
      # Note that loading grml's zshrc here will override NixOS settings such as
      # `programs.zsh.histSize`, so they will have to be set again below.
      source ${pkgs.grml-zsh-config}/etc/zsh/zshrc

      alias d='ls -lah'
      alias g=git

      # Increase history size.

      # Prompt modifications.
      # In current grml zshrc, changing `$PROMPT` no longer works,
      # and `zstyle` is used instead, see:

      # Disable the grml `sad-smiley` on the right for exit codes != 0;
      # it makes copy-pasting out terminal output difficult.
      # Done by setting the `items` of the right-side setup to the empty list
      # (as of writing, the default is `items sad-smiley`).
      # See:
      zstyle ':prompt:grml:right:setup' items

      # Add nix-shell indicator that makes clear when we're in nix-shell.
      # Set the prompt items to include it in addition to the defaults:
      # Described in:
      function nix_shell_prompt () {
        REPLY=''${IN_NIX_SHELL+"(nix-shell) "}
      grml_theme_add_token nix-shell-indicator -f nix_shell_prompt '%F{magenta}' '%f'
      zstyle ':prompt:grml:left:setup' items rc nix-shell-indicator change-root user at host path vcs percent
    programs.zsh.promptInit = ""; # otherwise it'll override the grml prompt = pkgs.zsh;


  • The code highlighting here on Discourse is broken, it does not understand the ''$VARIABLE escape to write a verbatim $ into the config in Nix multi-line strings ('').