nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
7.05k stars 1.82k forks source link

bug: PATH includes `/etc/profiles/per-user//bin` (missing username) #3341

Closed n8henrie closed 2 years ago

n8henrie commented 2 years ago

Are you following the right branch?

Is there an existing issue for this?

Issue description

I have home-manager.useUserPackages = true;, and I haven't changed this.

Inconsistently, I find that I'm missing packages that I have installed in my home-manager programs. Currently, I have neovim enabled and configured, but

$ nvim
The program 'nvim' is currently not installed. It is provided by
...

I can see that it's being installed:

$ ls /etc/profiles/per-user/$USER/bin/nvim
/etc/profiles/per-user/n8henrie/bin/nvim

When I investigate my $PATH, for some reason the /etc/profiles/per-user is missing my username:

$ printf "${PATH//:/'\n'}\n" | grep -e nix -e profile
/Users/n8henrie/.nix-profile/bin
/etc/profiles/per-user//bin
/nix/var/nix/profiles/default/bin

Any ideas what's going on?

Using as a nix-darwin module, flakes. It seems like this problem has happened to me and spontaneously(?) resolved 3 or 4 times now, I can't figure out what's going on.

Maintainer CC

No response

System information

 - system: `"aarch64-darwin"`
 - host os: `Darwin 21.6.0, macOS 12.6`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.11.0`
 - channels(n8henrie): `""`
 - channels(root): `"nixpkgs"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`
n8henrie commented 2 years ago
$ nix eval ~/.dotfiles?submodules=1#darwinConfigurations.NatePro.config.home-manager.users.n8henrie.home.profileDirectory
"/etc/profiles/per-user/n8henrie"

So profileDirectory is being set correctly.

n8henrie commented 2 years ago

User error.

Part of my bashrc explicitly sets my PATH with a hack[^0]:

NIXPATH=$(
  # shellcheck disable=SC2016
  env -i HOME="${HOME}" sh -c '
      for f in /etc/static/bashrc /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh; do
        [ -f "${f}" ] && . "${f}"
      done
      echo "${PATH}"
    '
)

PATH=${NIXPATH}:${PATH}

I needed to change it to env -i HOME="${HOME}" USER="${USER}" so that $USER would be available when setting up my environment.

[^0]: See also: https://github.com/NixOS/nix/issues/5950, https://github.com/NixOS/nix/issues/5298