I haven't found any info about handling temporary files in Nix derivations.
I found $TMP
and $TMPDIR
env vars, but they both point just to /tmp
, which is system global.
{
pkgs ? import <nixpkgs> {}
}:
pkgs.stdenv.mkDerivation {
pname = "show-tmp"
version = "0.1.0";
src = ./.;
configurePhase = ''
echo "tmp = $tmp; TMP = $TMP; TMPDIR = $TMPDIR"
'';
buildPhase = '':'';
installPhase = '':'';
}
Variable $tmp
is not defined inside mkDerivation. I would expect such thing, because other derivation scope vars follow low case style such as $out
.
The problem with /tmp is obvious - it is global directory. I need to worry about collisions and cleaning.
My derivation-hook archives a big folder tree.
If you're on Linux, don't worry. The Nix sandbox will give your build its own empty
/tmp
. It is removed when your derivation is done.On macOS,
$TMP
and$TMPDIR
are taken care of but/tmp
is a potential problem.How Nix creates a private /tmp on Linux
macOS Darwin, where Nix was installed in early 2020: