How to use nix shell inside nix develop?

Often times I enter a development shell of a derivation and later realize that I need some more tools like a debugger or so. So usually I’d do

[user@nixos:~]$ nix-shell '<nixpkgs>' -A hello

[user@nixos:~]$ nix-shell -p gdb

[user@nixos:~]$ 

This nested use of nix-shell seems to work fine although I don’t know whether that is the intended way of use.

However, with the new interface this happens:

[user@nixos:~]$ nix develop nixpkgs#hello

[user@nixos:~]$ nix shell nixpkgs#gdb

\[\][\[\]user@nixos:~]$\[\] 

At this last prompt, the shell is completely destroyed. Tab completion and line editing is entirely broken at that point.

What is the correct way to load additional packages into an existing development shell?

I can’t stand bash so I am often doing the following, which does not suffer from the problem:

$ nix develop nixpkgs#hello -c fish
$ which gcc
/nix/store/gk099cfff3s1g01adgvsn3957zabppvw-gcc-wrapper-10.2.0/bin/gcc
$ which gdb
/usr/bin/gdb
$ nix shell nixpkgs#gdb -c fish
$ which gdb
/nix/store/9h83vlhbszc44phpn4labxmlipfzjdz7-gdb-10.1/bin/gdb

But it would be still nice to make the bash sessions composable, in case one wants to work with the bash variables.

Very interesting, nix develop nixpkgs#hello -c bash instantaneously destroys the shell.

It seems like the problem is nixpkgs#bash, a build-time dependency of nixpkgs#hello, is run instead of nixpkgs#bashInteractive, so the completion and line editing isn’t really ‘destroyed’, it just isn’t there. This one does seem to work though:

nix develop nixpkgs#hello -c $SHELL

And so does the long-winded

nix develop nixpkgs#hello -c nix shell nixpkgs#bashInteractive -c bash
1 Like