Skip to content

Commit

Permalink
devbox: unset TMPDIR in shell/run environment (#691)
Browse files Browse the repository at this point in the history
Nix sets TMPDIR to its own path when building an environment and then
prints it with `print-dev-env`. Devbox "leaks" TMPDIR, meaning it takes
the TMPDIR from the parent shell and overwrites the Nix TMPDIR. However,
this doesn't work when TMPDIR isn't set in the parent shell, which is
the case in WSL and Docker.

This is a quick fix for just TMPDIR. We should double check the other
variables that `nix develop` unsets when there's more time to test.
  • Loading branch information
gcurtis committed Feb 25, 2023
1 parent e5b0710 commit c4de4dc
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/impl/devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,15 @@ func (d *Devbox) computeNixEnv(setFullPath bool) (map[string]string, error) {
}
}

// Hack to quickly fix TMPDIR being set to the temp directory Nix used
// in the build environment. When there's more time to test, we should
// probably include all of the variables that Nix ignores:
// https://github.com/NixOS/nix/blob/92611e6e4c1c5c712ca7d5f9a258640662d006df/src/nix/develop.cc#L291-L357
delete(env, "TEMP")
delete(env, "TEMPDIR")
delete(env, "TMP")
delete(env, "TMPDIR")

// Copy over (and overwrite) vars that we explicitly "leak", as well as DEVBOX_ vars.
for _, kv := range os.Environ() {
key, val, found := strings.Cut(kv, "=")
Expand Down

0 comments on commit c4de4dc

Please sign in to comment.