I have a flake that defines devShells.default = pkgs.mkShell {}
with shellHook
that exports PS1
variable. This works fine and the shell from nix develop
has this PS1
. But nix develop --command bash
does not recieve this shellHook
and thus there is no custom PS1
.
This is problematic because when I run VS Code inside a devShell
it not only launches extra shells with /bin/bash
, but also uses custom --init-file
. This makes it impossible to use wrapProgram
because this custom --init-file
always reads ~/.bashrc
. And use of may flake may have his PS1
set there.
Basically, I want to share this flake as a development environment and have all calls to bash inside this environment set a custom PS1
.
You might look at configuring PS1
based on values of environment variable. I use something like this to change colors of part of my prompt
interactiveShellInit = ''
### shell prompt
if [ -n "''${VCSH_REPO_NAME+x}" ]; then vPROMPT=".$VCSH_REPO_NAME"; fi
wd_clr=32
if [ 2 -lt ''${SHLVL} ]; then wd_clr=33; fi
if [ -v NIX_DEV_SHELL ]; then wd_clr=33; fi
export PS1='\[\033[2;32m\]\u@\h\[\033[0;33m\]$vPROMPT\[\033[00m\]:\[\033[0;'$wd_clr'm\]\w\[\033[00m\]\$ '
''
Problem is, I can’t set PS1 at all because it get overridden by one of user’s rc files (~/.bashrc
for example).
Consider configuring a custom variable as PS1
, and then assign PS1
from the custom variable in .bashrc
or elsewhere as needed. This means users of your flake would have to make a small change to their system to get your custom PS1
. This approach enables your users to customize their environment, taking your bits they like and dropping others. You just have to make it as easy as you can.
Another option might be to have your flake override whatever bash
is being run. But this may not be practical with VSCode – especially if it explicitly executes /bin/bash
instead of whatever bash
is on $PATH
. For that you’d have to get VSCode fixed. 
No, no, VS Code is fine, it launches the correct bash. But it supplies its own --rcfile
making things like this impossible. Could have been very elegant tho…
buildInputs = let
wrappedBash = pkgs.writeScriptBin "bash" ''
${pkgs.bashInteractive}/bin/bash --rcfile <(cat /etc/bash.bashrc ~/.bashrc; echo 'PS1="bleh >"') "$@"
'';
in [
wrappedBash
];
I obviously could ask users of my flake to add modifications and VS Code probably has some options in the settings, but I was wondering whenever there was a solution that wouldn’t require any extra actions from the user of the flake. Seems like there are non…