Zsh shell PROMPT customisation not working

I have a server with zsh as shell which I login as root to over ssh. I want to customise the PROMPT variable. This server does not have home manager and I want to keep it that way so it is lean.

I have tried:

programs.zsh.interactiveShellInit = ''
  PROMPT="%B%F{red}[%n@%m:%1d]$ %f%b";
'';

Which ends up in /etc/zshrc.
I have proved zsh is loading /etc/zshrc with an echo in interactiveShellInit block. However the PROMPT var (echo $PROMPT) is still set to “%n@%m:%~/ >” which i assume is the default.

Does anyone have this working?

My zsh configuration

programs.zsh = {
    enable = true;
    shellAliases = {
      lss = "ls -alh";
    };
    interactiveShellInit = ''
      # Set prompt string
    	PROMPT='%B%F{red}[%n@%m:%1d]$ %f%b'
    '';
  };

My current work around is to manually create the /root/.zshrc file with the PROMPT variable in it, as per below and that does work.

  system.activationScripts = {
    # Have to create .zshrc here as zsh.interactiveShellInit did not work
    zshrc = {
      text = ''
       echo -e "PROMPT='%B%F{red}[%n@%m:%1d]$ %f%b'" > /root/.zshrc
      '';
    };
  };

However that should not be necessary! :sweat_smile:

There is an option:
https://search.nixos.org/options?channel=unstable&show=programs.zsh.promptInit&from=0&size=30&sort=relevance&type=packages&query=zsh

1 Like

Oh great, I didn’t spot that option in the list yesterday :sweat_smile: that does the trick! Thanks heaps! :smile: