nix icon indicating copy to clipboard operation
nix copied to clipboard

nix not on PATH in tmux on standard Debian 12.11 multi-user install

Open dnadlinger opened this issue 7 months ago • 8 comments

Describe the bug

On a standard Debian 12.11 image, nix is not available inside tmux shells. This is because the Nix profile bin directories are not on the PATH, because the PATH gets reset in /etc/profile but __ETC_PROFILE_NIX_SOURCED is inherited.

Steps To Reproduce

  1. Start from a stock Debian Bookworm (current: 12.11) image.
  2. sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --daemon with default options.
  3. Reboot for good measure.
  4. Observe that nix --version succeeds on user's login shell, but not after tmux.

Expected behavior

I expect nix to be available, and any other executables in the profile. However, they are not, as /home/$USER/.nix-profile/bin:/nix/var/nix/profiles/default/bin are not prepended to $PATH in the inner shell.

This is because in /etc/profile, PATH is reset as follows:

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "$(id -u)" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi
export PATH

[…]

Yet __ETC_PROFILE_NIX_SOURCED=1 is inherited from the parent shell, so /etc/profile.d/nix.sh -> /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh returns immediately.

Since this is a very basic setup (no customisations made to the stock Debian install), I just expect this to work.

Metadata

nix-env (Nix) 2.29.0

dnadlinger avatar May 23 '25 21:05 dnadlinger

Same when logging in to Gnome via gdm and then opening a terminal. With direct login via TTY, nix and nix-installed programms are present.

db6edr avatar Jun 23 '25 12:06 db6edr

Same here.

msanft avatar Jul 10 '25 18:07 msanft

Same here, tmux 3.5a, zsh 5.9 (x86_64-debian-linux-gnu) and Linux kali 6.12.33+kali-amd64

z4rathustr4 avatar Jul 20 '25 21:07 z4rathustr4

workaround: run unset __ETC_PROFILE_NIX_SOURCED in tmux, then do bash. or putting it in your tmux startup command.

ezrizhu avatar Jul 31 '25 23:07 ezrizhu

@ezrizhu thanks for pointing this out. for anyone else interested, here is how I set this in my hm-config:

programs.bash.shellAliases.ta = "tmux attach || env -u __ETC_PROFILE_NIX_SOURCED tmux";

mcnesium avatar Sep 07 '25 14:09 mcnesium

Whoa, this started happening to me after Nix reinstall (Determinate Installer, MacOS). Seems a bit weird that "dirty tricks" are needed to get the nix environment in tmux, especially given that tmux itself is installed via home-manager.

There must be a better solution

aSapien avatar Nov 20 '25 15:11 aSapien

Whoa, this started happening to me after Nix reinstall (Determinate Installer, MacOS). Seems a bit weird that "dirty tricks" are needed to get the nix environment in tmux, especially given that tmux itself is installed via home-manager.

There must be a better solution

Seems like I was too quick to assume. I just needed to kill all the tmux sessions and start a new one. Everything works like a charm now.

aSapien avatar Nov 20 '25 16:11 aSapien

Issue is caused by 2b4e3fa1443c8d56ead43865adf037efa92c3fd7 Can we revert this? Having this check not always work is a better outcome than the paths not being set at all IMO.

MichielDerhaeg avatar Dec 02 '25 22:12 MichielDerhaeg

putting this in tmux.conf works -

set-option -g default-command "env -u __ETC_PROFILE_NIX_SOURCED $SHELL"

zedonix avatar Dec 16 '25 03:12 zedonix