Nushell broken in nix develop

I am trying to use nushell as my default shell, and I followed wiki, configured bash as a wrapper shell. Unfortunately, when I wanted to start to develop my project, I found that the environment variables are broken in nu. But after editing my nix config and launch nu manually, it works OK again. I don’t know why this happens. Is bash doing some initialization after executing .bashrc?

It depends. Bash has 3 different entrypoint files, all of which are executed under subtly different circumstances, sometimes together. The default behavior is also often overridden, because people don’t understand it, so many profile files just execute their alternatives, resulting in many confusing inheritance paths.

Additionally, sometimes people launch additional bash shells in their init scripts, or other tools run subshells which in turn may or may not have flags set that en-or disable certain init scripts, and then present them as if they were a “normal” shell.

.bashrc specifically will normally be skipped for non-interactive shells. Placing a nu exec in it is a good idea if you want to run nu as your true interactive shell, but you have to make sure that all bashes you execute are in fact interactive shells.

Basically, bash is used, and therefore abused, so much that it’s kind of unpredictable.


Personally, I use dash as my login shell, and configure it thus:

# ~/.profile
. "${config.home.profileDirectory}/etc/profile.d/hm-session-vars.sh"

export BROWSER='librewolf'
export VISUAL='emacsclient'
export EDITOR='emacsclient'
export ALTERNATE_EDITOR='emacs'
export VTERM='alacritty'
export ENV="$HOME/.config/dashrc"
# ~/.config/dashrc

# Ensure that e.g. tramp doesn't try to launch nu
if ! [ "$TERM" = "dumb" ]; then
    # Disable C-s freezing the terminal
    stty -ixon

    exec nu
fi

Besides being marginally faster at starting up, dash’ init behavior is a little more predictable, see the invocation heading on its man page.

Also, since bash isn’t in the loop, whenever I do get dropped into a POSIX shell that tells me that something I’m using is being silly, making it a little easier to debug these kinds of issues. The difference between something executing bash and dash is pretty obvious, too, so it serves as good disambiguation between the various things that can cause that.

2 Likes

Well, I can’t see when nu will be executed.

That happens in the second snippet:

Here

I know, but when is dashrc executed? Is the script stored in ENV executed automatically at some moment?

I’d just use direnv instead of nix develop, it should work with more shells.

I mean… Copying the manual entry I linked so that you don’t have to click on it:

If the environment variable ENV is set on entry to an interactive shell, or is set in the .profile of a login shell, the shell next reads commands from the file named in ENV. Therefore, a user should place commands that are to be executed only at login time in the .profile file, and commands that are executed for every interactive shell inside the ENV file. To set the ENV variable to some file, place the following line in your .profile of your home directory

ENV=$HOME/.shinit; export ENV

substituting for ‘’.shinit’’ any filename you wish.

I don’t know why, but somehow this does not work for me. Dash never executes .config/dashrc until I manually run the script.

I just fixed that problem by replacing “~/.config/dashrc“ with “$HOME/.config/dashrc“, and it works really well now.

2 Likes