PS1 on nix-shell


#1

So I’m trying to get my nix-shell PS1 prompt to tell me that I’m in a nix-shell

I tried

shellHook = ‘export PS1="$PS1:nix-shell> "’;

but I think my bashrc is probably overriding it, how do others set their PS1 as part of a nix-shell session?
I never know if I’m ‘in’ or ‘out’


#2

You could check for $IN_NIX_SHELL inside your bashrc:

if [[ -n "$IN_NIX_SHELL" ]]; then
  export PS1="$PS1:nix-shell>"
fi

#3

I use this one in the shellHook of shell.nix for example:
shellHook = "export PS1='\n\[\033[1;34m\][${name}:\w]\$\[\033[0m\]' "
It changes the prompt color and also shows the name of the derivation to indicate where I am.


#4

cool,

I settled on

if [[ -n "$IN_NIX_SHELL" ]]; then
	prompt_tag "(nix-shell)"
fi

where prompt_tag is from liquidprompt