Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom shell in nix-shell/nix run #2681

Closed

Conversation

haslersn
Copy link

@haslersn haslersn commented Feb 15, 2019

EDIT: Any changes to nix-shell have been removed from the PR. Only nix run is now affected.

  • Use $NIX_SHELL_INTERACTIVE_SHELL (if present) as interactive shell for nix-shell
  • Use $NIX_RUN_INTERACTIVE_SHELL (if present) as interactive shell for nix run

If --run, --command or -c are given, then bash is still used.

One could also consider those environment variables to be arbitrary default commands that are executed when nix-shell/nix run are ran interactive and without a command. However, I think the most common use case (by far) is to set them to a shell, hence the name [...]_INTERACTIVE_SHELL.

Tests:

I was unsuccessful adding tests to tests/nix-shell.sh. Any non-interactive test doesn't trigger the feature since it's only triggered in interactive shells.

Previous work:

Issue #419 (nix-shell ignoring SHELL enviroment variable) proposed to use $SHELL as interactive shell for nix-shell. This is of course not desirable if people depend on nix-shell always using bash. With this change however, the feature is optional since it uses previously unused environment variables.

@haslersn haslersn force-pushed the enhancement/custom-shell-for-nix-shell branch 4 times, most recently from 00c6f75 to a96c777 Compare February 15, 2019 07:58
@matthewbauer
Copy link
Member

I think this makes sense with nix run. But we use a lot of Bash-only stuff in Nixpkgs, so nix-shell seems like it would be broken.

@haslersn haslersn force-pushed the enhancement/custom-shell-for-nix-shell branch from a96c777 to 0f96d17 Compare February 15, 2019 23:42
@haslersn
Copy link
Author

haslersn commented Feb 15, 2019

But we use a lot of Bash-only stuff in Nixpkgs, so nix-shell seems like it would be broken.

bash-only install scripts of course wouldn't run. However, why would you disallow using nix-shell with another shell, just because there use cases, where bash is needed?

@LnL7
Copy link
Member

LnL7 commented Feb 16, 2019

A nix-shell is mainly intended for reproducing builds interactively, setting that variable completely breaks that which is a bad user experience IMHO. There are already tools, like direnv, that handle the usecase you are looking for.

@haslersn haslersn force-pushed the enhancement/custom-shell-for-nix-shell branch from 0f96d17 to 19d1ef5 Compare February 16, 2019 13:29
@haslersn
Copy link
Author

A nix-shell is mainly intended for reproducing builds interactively, setting that variable completely breaks that which is a bad user experience IMHO. There are already tools, like direnv, that handle the usecase you are looking for.

direnv looks appropriate for the job.

Since that's the common oppinion here, I'm no going to remove the nix-shell changes from the PR.

@haslersn haslersn force-pushed the enhancement/custom-shell-for-nix-shell branch from 19d1ef5 to b552da9 Compare February 16, 2019 13:59
* Use `$NIX_RUN_INTERACTIVE_SHELL` (if present) as interactive shell for `nix run`

If `--command` or `-c` are given, then bash is still used.

One could also consider those environment variables to be arbitrary
default commands that are executed when `nix run` is ran interactively
and without a command. However, I think the most common use case (by
far) is to set them to a shell, hence the name `[...]_INTERACTIVE_SHELL`.

Previous work:

Issue NixOS#419 (nix-shell ignoring SHELL enviroment variable) proposed to
use `$SHELL` as interactive shell for `nix-shell`. This is of course
not desirable for `nix-shell` since it's mainly inteded for reproducing
builds with bash build scripts. For `nix run` such a feature seems
however appropriate.
@haslersn haslersn force-pushed the enhancement/custom-shell-for-nix-shell branch from b552da9 to a14527a Compare February 16, 2019 14:01
@hyperfekt
Copy link

hyperfekt commented Feb 26, 2019

Given that, to my understanding, nix run is not used for building, and there is no analogous variable for nix-shell anymore, could it use $SHELL instead, and provide a good experience for users by default?

@haslersn
Copy link
Author

Certainly, but there's some possibility that it would break scripts that somehow use nix run fake-interactively. Not sure though whether such things exist.

@hyperfekt
Copy link

hyperfekt commented Mar 23, 2019

Because of Github's inaccurate search it's impossible to verify this without automating it but every single use of nix run in a script in a cursory glance is with --command.

@hyperfekt
Copy link

hyperfekt commented May 22, 2020

Requesting this to be closed, seems to have been made obsolete by #3477.

@haslersn haslersn closed this May 23, 2020
@haslersn haslersn deleted the enhancement/custom-shell-for-nix-shell branch May 23, 2020 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants