-
Notifications
You must be signed in to change notification settings - Fork 184
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
shell,nix: set original PATH at start of init file #57
Conversation
This fixes a bug that causes the devbox shell's init to fail when the user's rcfile tries to call a command outside of devbox. For example, the following line in a ~/.bashrc will trigger an error if the devbox doesn't have Go installed: export PATH="$(go env GOPATH):$PATH" This is because we're adding the ORIGINAL_PATH at the end of their shell init script, which means that anything before that only see Nix packages. Fix this by adding a pre-init hook that lets us restore the PATH before the user's rcfile, while still forcing Nix packages to come first in the post-init hook.
@LucilleH do you mind running this to verify that |
# but prefer anything installed by Nix. | ||
export PATH="$PURE_NIX_PATH:$ORIGINAL_PATH" | ||
sh.PreInitHook = ` | ||
# Update the $PATH so that the user's init script has access to all of their |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should both the PreInit and PostInit hooks set the path to: $PURE_NIX_PATH:$ORIGINAL_PATH
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just switched both hooks to use the Nix packages.
I wasn't sure what the correct behavior should be:
- Prefer the non-devbox PATH to guarantee compatibility with the user's rcfile.
- Prefer the devbox PATH so that hooks use the Nix packages.
@LucilleH are you able to test again? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worked when I ran it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
if runErr != nil && d.Debug() { | ||
log.Printf("Error: %+v\n", runErr) | ||
strVal := "" | ||
if d.flag.Changed { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work. preRun runs before the command so the flag is not set yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well that explains it. I'll put up another PR to clean up the debug stuff and make the flag work.
var enabled bool | ||
|
||
func init() { | ||
enabled, _ = strconv.ParseBool(os.Getenv("DEBUG")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be DEVBOX_DEBUG ?
Summary
This fixes a bug that causes the devbox shell's init to fail when the user's rcfile tries to call a command outside of devbox. For example, the following line in a
~/.bashrc
will trigger an error if the devbox doesn't have Go installed:This is because we're adding the ORIGINAL_PATH at the end of their shell init script, which means that anything before that only see Nix packages.
Fix this by adding a pre-init hook that lets us restore the PATH before the user's rcfile, while still forcing Nix packages to come first in the post-init hook.
How was it tested?
Added a command that's only available outside of devbox to my ~/.bashrc and made sure it was called successfully.