If we put an overlayfs on /var because the user provided files in
/var via their sandbox tree, make sure /var/tmp is not an overlayfs
unless really required so tools like systemd-repart can make full
use of the underlying filesystem features which are disabled if
/var/tmp is on an overlayfs.
else:
cmdline += ["--tmpfs", Path("/") / d]
+ # If we put an overlayfs on /var, and /var/tmp is not in the sandbox tree, make sure /var/tmp is a bind mount
+ # of a regular empty directory instead of the overlays so tools like systemd-repart can use the underlying
+ # filesystem features from btrfs when using /var/tmp.
+ if overlay and not (overlay / "var/tmp").exists():
+ tmp = stack.enter_context(vartmpdir())
+ cmdline += ["--bind", tmp, "/var/tmp"]
+
yield [*cmdline, *options, "--"]