SSH, Flake, and Tmux Weirdness


I have started adding flake.nix files to my projects, and really like the overall ergonomics that it provides. I have run into an issue. When connected to a NixOS machine using ssh, nix develop along with tmux are causing strange behavior.

  1. When using a nix develop shell environment within tmux, the TMPDIR being used does not exist but the parent TMPDIR does.
# /path/to/project
tmux new-session -s <project>
# inside tmux
nix develop # tries to use a TMPDIR that does not exist within another
            # TMPDIR that exists
# error: creating temporary file '/tmp/nix-shell.dZmZup/nix-shell.EkR9Tx':
# No such file or directory

# Expected behavior: is for there to be a single nix-shell TMPDIR for
# that tmux window
  1. When using tmux within a nix develop shell environment, the TMPDIR is correct but I get
# /path/to/project
nix develop # runs fine
tmux new-session -s <project>
cargo build # build step for the project using pkg from buildInputs
# error: couldn't create a temp dir: No such file or directory (os error 2)
# at path "/tmp/nix-shell.dZmZup/rustcZLnBTI"

# Expected behavior: is for there to be a single nix-shell TMPDIR
# for the tmux session, and for the build step to complete

I mentioned the ssh part because it seems to be relevant, I tested both methods and they work on my local NixOS machine. There is also a chance that both errors are not related but I do not know enough to be sure.

Any help or guidance is appreciated.

Update: flake.nix seemed relevant, and make it easier if someone wanted to attempt to reproduce the error.

  description = "rust-dev";

  inputs =
		nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";

  outputs = { self, nixpkgs, ... }@inputs:
		system = "x86_64-linux";
		pkgs = nixpkgs.legacyPackages.${system};
		devShells.x86_64-linux.default = pkgs.mkShell rec {
			buildInputs = with pkgs; [
				# rust deps
				# dev deps
				pkg-config # general requirement for *-sys crates
				tmux entr # QoL
				gdb valgrind evcxr # debugging

			shellHook = ''

			export CARGO_HOME=$root_dir/cargo
			export PATH=$CARGO_HOME/bin:$PATH
			export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${builtins.toString (pkgs.lib.makeLibraryPath buildInputs)}";

			if [ ! -d $root_dir ]; then
				echo tools_dir missing, creating
				mkdir $root_dir

			exec fish

Restarting the virtual machine seems to have fixed the issue. Must have been some cruft since I hadn’t restarted the virtual machine in a while.

From a fresh restart on NixOS 23.11 over ssh, nix develop works well with tmux in both of the configurations mentioned above.