NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.86k stars 1.52k forks source link

Nix wipes top-level $TEMPDIR, disallowing other processes to create temporary files #11929

Open iggy-da opened 1 day ago

iggy-da commented 1 day ago

The hook _nix_shell_clean_tmpdir may execute rm -rf $TEMPDIR. Observed on Ubuntu 24.04 and MacOS when using nix with direnv.

This happens when this tmpDir variable is assigned the $TEMPDIR path itself, rather than a temp subdirectory.

The $TEMPDIR is then rm -rfed here https://github.com/NixOS/nix/blob/32becc87fef7340600df75ffed6e7c6bc56aa827/src/nix-build/nix-build.cc#L601

This means processes trying to create temporary files inside $TEMPDIR (such as, for example, docker), will fail.

Fix: This tmpDir variable should never be allowed to be the top-level $TEMPDIR.