In NixOS, the sandbox feature during builds ensures reproducibility by isolating the build process from the host system. The Filesystem Hierarchy Standard (FHS) is generally not followed by NixOS natively, as everything is stored in the /nix/store with symlinks for compatibility, which can cause issues for programs expecting a standard FHS layout. The TMPDIR environment variable is relevant to how applications handle temporary files, and its behavior can differ between the default system environment and specific Nix shells.
Sandboxing and FHS
Sandboxing The Nix package manager strictly sandboxes package builds to guarantee that the resulting package is reproducible and only depends on specified inputs. This isolation means the build environment is a minimal, clean slate, preventing access to most host system files or non-declared dependencies.
TMPDIR environment variable specifies where an application should create temporary files. Its interaction with the Nix sandbox and FHS environments can lead to issues:
Default Behavior On a standard NixOS system, TMPDIR might not be set by default in the global system environment.
/* Create a writable /tmp in the chroot. Many builders need
this. (Of course they should really respect $TMPDIR
instead.) */
#nixos sandbox #tmpfs
https://github.com/NixOS/nix/blob/340f831ebe9d74659b84667b96251b7ab0edd09d/src/libstore/build/local-derivation-goal.cc#L609-L614
besides #lix has something tempting for everyone including nixos
https://github.com/NixOS/nix/issues/13462#issuecomment-3137584843