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

devbox shell gives no indication #25

Closed
bogosj opened this issue Aug 27, 2022 · 6 comments
Closed

devbox shell gives no indication #25

bogosj opened this issue Aug 27, 2022 · 6 comments

Comments

@bogosj
Copy link

bogosj commented Aug 27, 2022

When I start a devbox shell I see no visual indication that I'm in the shell, but it definitely is working

image

# type lazygit
lazygit is hashed (/nix/store/alnmpxx1njfnv671sgnqxrws1bbari6r-lazygit-0.35/bin/lazygit)

# echo $PS1
\n\d \t\n\e[37;44m[\u@\h:\w]\[\e[00m\] \[\e[91m\]$(parse_git_branch)\[\e[00m\]\n#

# type parse_git_branch
parse_git_branch is a function
parse_git_branch ()
{
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
@loreto
Copy link
Contributor

loreto commented Aug 28, 2022

@bogosj , may I ask what shell you use? What do you see if you run echo $SHELL? Is it bash?

@bogosj
Copy link
Author

bogosj commented Aug 28, 2022

Yes, bash.

@bogosj
Copy link
Author

bogosj commented Aug 28, 2022

I tried zsh, same situation:

export SHELL=/usr/bin/zsh
zsh
bogosj@debian ~ % devbox shell
Installing nix packages. This may take a while...
Starting a devbox shell...
bogosj@debian ~ % type lazygit
lazygit is /nix/store/alnmpxx1njfnv671sgnqxrws1bbari6r-lazygit-0.35/bin/lazygit
bogosj@debian ~ % exit
bogosj@debian ~ % 

@loreto
Copy link
Contributor

loreto commented Aug 28, 2022

Yeah, we need to fix on our side. I just wanted to know which shell so I can make sure it works for it. I'll take a look this coming week.

@acrefoot
Copy link

acrefoot commented Aug 29, 2022

Same issue with the prompt not being overridden on Mac :)

acrefoot@MacBook ~ % echo $SHELL
/bin/zsh
acrefoot@MacBook ~ % devbox shell
Installing nix packages. This may take a while...
Starting a devbox shell...
Restored session: Mon Aug 29 14:45:47 EDT 2022
acrefoot@MacBook ~ % echo $shell
/nix/store/7k3nqj8bpmpsk5vf8933hvs12q9307vc-bash-5.1-p16/bin/bash

@loreto loreto pinned this issue Sep 1, 2022
gcurtis added a commit that referenced this issue Sep 1, 2022
This fixes an issue where the user's rc (~/.bashrc, ~/.zshrc, etc.)
files were prepending to the devbox shell PATH. This can cause the
shell to unexpectedly run the non-devbox version of programs. It's
especially noticeable with some version managers that point the PATH at
their shims so they can control which version of a program is run.

The basic steps that result in this issue are:

1. Devbox launches Nix, which sets the PATH to point to the Nix store.
2. From within Nix, we launch the user's default shell.
3. The shell runs the user's init files and stomps on the Nix PATH.

Fixing this is a little tricky because there's no straightforward way to
run additional commands _after_ the shell runs the init files. Instead,
we need to copy the user's init files and append to them. Doing this
requires knowing how each shell handles initialization, so we need to
special-case the more common shells by performing the following steps:

1. Attempt to detect the user's default shell via the SHELL env var (we
   may add more sophisticated detection later).
2. If the shell is recognized as bash, zsh, ksh, dash, ash or sh, copy
   over the user's corresponding init files to a temp directory and
   append our own commands to it.
3. Build an `exec` shell command that invokes the new shell and tells it
   to run our temp init file instead of the user's.

If we can't detect the shell, we fall back to launching a vanilla Nix
shell. If we don't recognize the detected shell, we fall back to
launching it without overriding the init files.

Finally, since we now have a way of running our own commands in the
user's shell, we can change the PS1 prompt to show the user that
they're in devbox.

Fixes #17, #25, #44, #46.
gcurtis added a commit that referenced this issue Sep 1, 2022
This fixes an issue where the user's rc (~/.bashrc, ~/.zshrc, etc.)
files were prepending to the devbox shell PATH. This can cause the
shell to unexpectedly run the non-devbox version of programs. It's
especially noticeable with some version managers that point the PATH at
their shims so they can control which version of a program is run.

The basic steps that result in this issue are:

1. Devbox launches Nix, which sets the PATH to point to the Nix store.
2. From within Nix, we launch the user's default shell.
3. The shell runs the user's init files and stomps on the Nix PATH.

Fixing this is a little tricky because there's no straightforward way to
run additional commands _after_ the shell runs the init files. Instead,
we need to copy the user's init files and append to them. Doing this
requires knowing how each shell handles initialization, so we need to
special-case the more common shells by performing the following steps:

1. Attempt to detect the user's default shell via the SHELL env var (we
   may add more sophisticated detection later).
2. If the shell is recognized as bash, zsh, ksh, dash, ash or sh, copy
   over the user's corresponding init files to a temp directory and
   append our own commands to it.
3. Build an `exec` shell command that invokes the new shell and tells it
   to run our temp init file instead of the user's.

If we can't detect the shell, we fall back to launching a vanilla Nix
shell. If we don't recognize the detected shell, we fall back to
launching it without overriding the init files.

Finally, since we now have a way of running our own commands in the
user's shell, we can change the PS1 prompt to show the user that
they're in devbox.

Fixes #17, #25, #44, #46.
gcurtis added a commit that referenced this issue Sep 1, 2022
This fixes an issue where the user's rc (~/.bashrc, ~/.zshrc, etc.)
files were prepending to the devbox shell PATH. This can cause the
shell to unexpectedly run the non-devbox version of programs. It's
especially noticeable with some version managers that point the PATH at
their shims so they can control which version of a program is run.

The basic steps that result in this issue are:

1. Devbox launches Nix, which sets the PATH to point to the Nix store.
2. From within Nix, we launch the user's default shell.
3. The shell runs the user's init files and stomps on the Nix PATH.

Fixing this is a little tricky because there's no straightforward way to
run additional commands _after_ the shell runs the init files. Instead,
we need to copy the user's init files and append to them. Doing this
requires knowing how each shell handles initialization, so we need to
special-case the more common shells by performing the following steps:

1. Attempt to detect the user's default shell via the SHELL env var (we
   may add more sophisticated detection later).
2. If the shell is recognized as bash, zsh, ksh, dash, ash or sh, copy
   over the user's corresponding init files to a temp directory and
   append our own commands to it.
3. Build an `exec` shell command that invokes the new shell and tells it
   to run our temp init file instead of the user's.

If we can't detect the shell, we fall back to launching a vanilla Nix
shell. If we don't recognize the detected shell, we fall back to
launching it without overriding the init files.

Finally, since we now have a way of running our own commands in the
user's shell, we can change the PS1 prompt to show the user that
they're in devbox.

Fixes #17, #25, #44, #46.
@loreto
Copy link
Contributor

loreto commented Sep 2, 2022

@gcurtis merged a fix. It's going out on the next release. Closing.

@loreto loreto closed this as completed Sep 2, 2022
@loreto loreto unpinned this issue Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants