nix: load env before Nix shellHook; clean up PATH #124
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Depends on #106.
When launching a devbox shell, we need to configure the environment so that things don't break in weird ways. We need to copy some variables directly (like LANG/LC_* locale variables) and others we need to modify (such as PATH). Our current method of setting these variables has a few problems:
devbox run
or piping scripts to stdin.To fix this, instead set environment variables when launching the
nix-shell
process and use the--keep
flag to tell Nix to propagate them into the new shell. This ensures that the Nix shell, the Nix shell hooks, and the devbox shell all get the correct environment. SeeenvToKeep
for the full list of variables we copy over.Setting the correct PATH is the most complicated part of this change, but to summarize:
devbox shell
, we take a snapshot of PATH and NIX_PROFILES.PATH="$PATH:$PARENT_PATH
.This ensures that the PATH is correct by the time the devbox shell runs. However, there's still the possibility that the user's shellrc will change the PATH again. This is common with version managers like asdf. To make sure Nix packages always have priority before giving the user a prompt, we run some commands in the devbox shellrc that find all PATH entries that are in the Nix store and put them in front of everything else.
How was it tested?
go test ./...
and running adevbox shell
.