My solution didnât work as I kept debugging this with Visual Studio Code. The following does work, but I do not understand how and whether itâs a solid solution. I am not sure why nix-shell doesnât require this, but nix develop then does:
buildInputs = [ pkgs.bashInteractive ];
To more reliably check the Bash binary used, we can use /proc/[pid]/exe. Combined with the previous solution, I end up with an interactive Bash:
Thanks for linking to that issue. Not 100% sure itâs the same issue, but seems like it. The author of the issue doesnât state what he means by âbrokenâ.
My issue is about an non-interactive/dumb shell that inserts literal tabs. There is a similar issue where auto-completion doesnât work for any software not specified in mkShell. So in that case git would not auto-complete anyway, because its share directory is not listed in $XDG_DATA_DIRS.
I am not sure what the underlying problem is, if there is any real problem here. Is nix develop pure (or nix-shell)? You can access tools from the âparentâ environment, like git, which begs the question why git is in $PATH, but its share directory not in $XDG_DATA_DIRS.
@b-zee@cdepillabout The above line used to work for me (although I put it under nativeBuildInputs, but I donât think it makes any difference for final.myHaskellPkgs.shellFor).
But it no longer works. Iâm now on a later nixpkgs commit from June 2024.
Did you find a more recent working solution to the problem? The problem, to recap, is a dysfunctional bash shell within a ânix developâ shell (strange chars showing up, no tab completion, etc.).
Also experiencing this issue on nixos-unstable. Weirdly, this used to just work, but this morning I launched a nix develop and my starship prompt blew up. Simply adding the bashInteractive package to the build deps doesnât solve it. It seems to work ok if I just run nix develop and work directly in there, but I was running zellij and having it launch a sub-shell causes the problem.
This shellHook solution was mentioned in the OP. Iâve now checked (3,5 years) later and it seems like some behavior has changed. Setting shellHook will indeed make the nix develop shell use interactive Bash.
However, the problem with VS Code et al still exists as long as the bashInteractive package is not included in the shellâs PATH.
The problem is that shells spawned from nix develop will use a noninteractive shell.
$ nix develop
$ type -a bash
bash is /nix/store/4fvc5fm8bszmkydng1ivrvr5cbvr1g60-bash-5.2p37/bin/bash
bash is /run/current-system/sw/bin/bash
$ bash
# 'Dumb' shell, e.g. pressing arrow keys yields the following:
$ ^[[D^[[A^[[C^[[B
While if the buildInputs includes bashInteractive, it works (notice the interactive Bash in the type output):
$ nix develop
$ type -a bash
bash is /nix/store/c3ym86hnrsh03k11mhbvvcw7f0y403vr-bash-interactive-5.2p37/bin/bash
bash is /nix/store/4fvc5fm8bszmkydng1ivrvr5cbvr1g60-bash-5.2p37/bin/bash
bash is /run/current-system/sw/bin/bash
$ bash
# Arrow keys (history) and autocompletion (using tabs) works!
(edit)
I have just learned the common way to spawn a subshell in a generic way is to call $SHELL. That makes sense as it will use the same as the parent shell. Perhaps VS Code is at fault here, as it apparently does not call $SHELL but somehow detects and regularly calls bash.