nix-build/nix-shell tmpdir unnecessarily long #1044

Open
opened 2025-11-21 11:59:02 +00:00 by pennae · 3 comments
Owner

TMPDIR=/tmp/nix-shell-31cm5aj8fp7p0395f0lb055n23/build-top-3n5jpa6cl9nszvxjl8kmjnc4hn is an unnecessarily long tempdir for builds or shells. the second random bit is unnecessary because the first random bit already guarantees uniqueness. this is ironic because the change to this happened to make darwin paths shorter for unix socket reasons, but now anything built in a shell that places unix sockets in a tmpdir only has 30(ish) bytes total for the unix socket path where previously it could have had a lot more

cc @emilazy

`TMPDIR=/tmp/nix-shell-31cm5aj8fp7p0395f0lb055n23/build-top-3n5jpa6cl9nszvxjl8kmjnc4hn` is an unnecessarily long tempdir for builds or shells. the second random bit is unnecessary because the first random bit already guarantees uniqueness. this is ironic because the change to this happened to make darwin paths shorter for unix socket reasons, but now anything built in a shell that places unix sockets in a tmpdir only has 30(ish) bytes *total* for the unix socket path where previously it could have had a lot more cc @emilazy
Owner

We get very different values with nix-shell than with nix-build. nix-build -E 'with import <nixpkgs> { }; runCommand "foo" { } "declare -p TMPDIR"' yields declare -x TMPDIR="/nix/var/nix/b/0fkd0xmsly1p4pqf6fi05isy1s", but nix-shell --run 'declare -p TMPDIR' -p yields that long as fuck path on Linux, but on my macOS machine it yields my normal shell's TMPDIR, unless I unset it first

$ nix-shell --run 'declare -p TMPDIR' -p
declare -x TMPDIR="/var/folders/jz/tbv2q66167q5k8v_xtz726q80000gn/T/"

$ env -u TMPDIR nix-shell --run 'declare -p TMPDIR' -p
declare -x TMPDIR="/private/tmp/nix-shell-68brq2c7w31ppr2zm6q3p43f7g/build-top-3p2bab9aswz49j9894w2f7a1l3"
We get very different values with `nix-shell` than with `nix-build`. `nix-build -E 'with import <nixpkgs> { }; runCommand "foo" { } "declare -p TMPDIR"'` yields `declare -x TMPDIR="/nix/var/nix/b/0fkd0xmsly1p4pqf6fi05isy1s"`, but `nix-shell --run 'declare -p TMPDIR' -p` yields that long as fuck path on Linux, but on my macOS machine it yields my normal shell's `TMPDIR`, *unless* I unset it first ```bash $ nix-shell --run 'declare -p TMPDIR' -p declare -x TMPDIR="/var/folders/jz/tbv2q66167q5k8v_xtz726q80000gn/T/" $ env -u TMPDIR nix-shell --run 'declare -p TMPDIR' -p declare -x TMPDIR="/private/tmp/nix-shell-68brq2c7w31ppr2zm6q3p43f7g/build-top-3p2bab9aswz49j9894w2f7a1l3" ```
Owner

This is due to my nix-shell's fixes, $NIX_BUILD_TOP is a temporary directory in the tmpDirRoot now if no $TMPDIR is provided to avoid the fallback on /tmp, causing things like /tmp/env-vars to be written and breaking the shell.

We could rebase the build top directory one directory above, there's nothing that forces it to live inside tmpDirRoot per se, saving 36 chars again.

This is due to my nix-shell's fixes, `$NIX_BUILD_TOP` is a temporary directory in the tmpDirRoot now if no `$TMPDIR` is provided to avoid the fallback on `/tmp`, causing things like `/tmp/env-vars` to be written and breaking the shell. We could rebase the build top directory one directory above, there's nothing that forces it to live inside tmpDirRoot per se, saving 36 chars again.
Author
Owner

we could also call it just build-top instead of appending a long-ass random string, that would also help a lot

we could also call it just `build-top` instead of appending a long-ass random string, that would also help a lot
Sign in to join this conversation.
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lix-project/lix#1044
No description provided.