Missing $TEMPDIR after entering nix-shell

I have a very strange problem on a new Ubuntu 24.04 installation. I have installed nix (package manager). I use the following shell.nix file:

{ pkgs ? import  <nixpkgs> {} }:
  pkgs.mkShell {
    shellHook = ''
        echo $TEMPDIR;
        ls $TEMPDIR;
    '';
}

I receive the following output when using nix-shell:

/tmp/nix-shell-235409-0

<some ls files output>

The $TEMPDIR directory clearly exists when the shell is built, but it is missing afterwards!

ls $TEMPDIR
ls: cannot access '/tmp/nix-shell-235409-0': No such file or directory

This breaks many build tools as they expect the temp directory to exist.

Any idea what could be the culprit?

Edit: This might be related: `use nix` breaks `mktemp` with Nix 2.24+ on macOS · Issue #1345 · direnv/direnv · GitHub