jetify-com / devbox

Instant, easy, and predictable development environments
https://www.jetify.com/devbox/
Apache License 2.0
7.83k stars 187 forks source link

Add ability to set the shell #2148

Open scottTomaszewski opened 2 weeks ago

scottTomaszewski commented 2 weeks ago

What problem are you trying to solve?

In the init_hook I would like to source some scripts containing helper utilities that are written in bash. In devbox run the shell is sh whereas devbox shell the shell is inherited from the caller's shell.

This behavior was confirmed in discord:

We designed it this way initially to make run calls more portable  and consistent. The thinking was that devbox run (especially if used in CI) would use a consistent shell and not be affected by a users specific settings, while devbox shell would use the users shell

which make sense, but if I wanted a consistent shell environment across both devbox shell and devbox run it would be nice to have a way to set that.

More discussion:

What solution would you like?

Ideally, the solution would be to have support for overriding the default shell for devbox shell and devbox run. For (a contrived) example:

{
  "$schema":  "https://raw.githubusercontent.com/jetify-com/devbox/0.11.0/.schema/devbox.schema.json",
  "packages": ["bash@latest"],
  "shell": {
    "exec": {
      "shell": "/bin/bash --rcfile something.bash",
      "run": "BASH_ENV=something.bash /bin/bash -c"
    },
    "init_hook": [
      "ps -p $$",
      "source .bootstrap.sh"
    ],
    ...

Alternatives you've considered

Lagoja commented 2 weeks ago

I think this is a really good suggestion, and it would help with some shell incompatibility bugs we've seen in the past.

I think I would tweak the proposal to allow the user to specify a shell package they want to install and use as well. For example (not final):

  "shell": {
    "package": "bash@5.1"
    "exec": {
      "shell": "bash --rcfile something.bash",
      "run": "BASH_ENV=something.bash bash -c"
    },

Would install Bash 5.1 from nixpkgs and then run shell/commands/services in that shell. This way you could write zsh/bash/fish specific scripts, and have it work across systems regardless of the user's host shell.