Skip to content

Commit c4de4dc

Browse files
authored
devbox: unset TMPDIR in shell/run environment (#691)
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.
1 parent e5b0710 commit c4de4dc

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

internal/impl/devbox.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,15 @@ func (d *Devbox) computeNixEnv(setFullPath bool) (map[string]string, error) {
780780
}
781781
}
782782

783+
// Hack to quickly fix TMPDIR being set to the temp directory Nix used
784+
// in the build environment. When there's more time to test, we should
785+
// probably include all of the variables that Nix ignores:
786+
// https://github.com/NixOS/nix/blob/92611e6e4c1c5c712ca7d5f9a258640662d006df/src/nix/develop.cc#L291-L357
787+
delete(env, "TEMP")
788+
delete(env, "TEMPDIR")
789+
delete(env, "TMP")
790+
delete(env, "TMPDIR")
791+
783792
// Copy over (and overwrite) vars that we explicitly "leak", as well as DEVBOX_ vars.
784793
for _, kv := range os.Environ() {
785794
key, val, found := strings.Cut(kv, "=")

0 commit comments

Comments
 (0)