Proposal: shellHook support for non-bash shells for nix develop

hello! i’m wondering if anyone has any feedback regarding a feature i’ve been thinking about.

proposal

currently, nix develop executes all shellHook code using bash. nix develop’s flexibility and usefulness could be extended to other shells with the inclusion of two new mkShell attributes:
shellHookShell - the shell with which to run shellHook commands, and
shellPackages - packages to be made accessible before shellHook is run.
browsing this thread, i was a little surprised to see that this functionality hasn’t already been implemented.

motivation

as of right now, nix develop’s usage of bash can be inconvenient for developers who rely on other, more modern shells. this would reduce the overhead required to manually enter into one’s preferred shell via nix develop --command <desired shell>. it would also allow and encourage developers to more declaratively set up their non-bash shell environments.
the most prevalent existing workaround (aliasing nix develop with --command <desired shell>) is not ideal: not only does it add boilerplate, but shellHook commands are not applied to the spawned instance of the desired shell, inadvertently reducing declarativity.

usage mockup

flake.nix snippet

pkgs.mkShell {
    name = "example_shell";
    shellPackages = [ pkgs.fish ];
    shellHookShell = pkgs.fish;
    shellHook = ''
        echo "hello from fish :3"
    '';
}

questions

does this seem like something that could be reasonably implemented?
ultimately, is this something that i should pursue/consider making an RFC for?

The problem is every shell needs to be special-cased because every shell operates differently.
I don’t know that this would be a very maintainable structure.

If you really want to use a different shell, I’d use direnv or something similar that uses nix print-dev-env that in turn allows you to use the shell of your choice.

1 Like

understood, thank you for your reply!! i’ll take a closer look at direnv.