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


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


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
$ which gdb
$ nix shell nixpkgs#gdb -c fish
$ which 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