Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problems with PATH order, when using as nixos-module. #550

Closed
maralorn opened this issue Jan 24, 2019 · 6 comments · Fixed by NixOS/nixpkgs#66425
Closed

problems with PATH order, when using as nixos-module. #550

maralorn opened this issue Jan 24, 2019 · 6 comments · Fixed by NixOS/nixpkgs#66425

Comments

@maralorn
Copy link
Contributor

Since I upgraded my nixos to 18-09 I have the following problem:
My PATH contains the following 3 entries in this order:

... /home/maralorn/.nix-profile/bin: ... :/run/current-system/sw/bin:/etc/profiles/per-user/maralorn/bin

So when using home-manager manually user installed packages take precedence over system packages because they land in .nix-profile. But when using home-manager as a system module, the system binaries take precedence.
There are of course easy workarounds for this. (Manually changing the PATH.)
But I am not sure what the best solution to this problem is and how to fix it in home-manager. Is this maybe a sign that we shouldn't install the user-environment to /etc/profiles/per-user/?

I'd be glad for input. Thanks for home-manager. It's awesome!

@rycee
Copy link
Member

rycee commented Jan 24, 2019

Thanks for the kind words!

I think this is a bug in NixOS and there is not much Home Manager can do to solve this in an elegant manner.

The /etc/profiles/per-user environment profile is set in users-groups.nix: https://github.com/NixOS/nixpkgs/blob/b5a42132d57f26b954d4c6d42f07fcb60dbff799/nixos/modules/config/users-groups.nix#L567

while the others are defined together in environment.nix: https://github.com/NixOS/nixpkgs/blob/b5a42132d57f26b954d4c6d42f07fcb60dbff799/nixos/modules/programs/environment.nix#L26-L30

The PATH variable is assembled from these profiles. Unfortunately since they are defined separately they don't show up in the "logical order" but in the module system "merge order". I don't know the reason for separating the definitions, it seems to me possible to simply have

environment.profiles =
  [ "$HOME/.nix-profile"
    "/etc/profiles/per-user/$USER"
    "/nix/var/nix/profiles/default"
    "/run/current-system/sw"
];

in environment.nix and not set it at all in users-groups.nix.

@oxij Found you in git blame where you made a cleanup in the users-groups.nix file. Can you think of a reason why we couldn't do the above change?

@Shados
Copy link

Shados commented May 31, 2019

@rycee "merge order" for list options is not arbitrary; you can manipulate it with mkOrder (or the simple wrappers mkBefore and mkAfter, none of which are really documented, so see <nixpkgs/lib/modules.nix> for details).

You could PR a nixpkgs change to do something like make the users-groups.nix line environment.profiles = mkBefore [ "$HOME/.nix-profile" "/etc/profiles/per-user/$USER" ]; and remove the first from environment.nix. This would seem reasonable to me (it is surprising to have more-specific per-user packages overriden by generic system-wide packages!).

You could also add that same definition in home-manager's nixos module. Which would work fine, but would mean those two directories would appear in $PATH twice :). That could slightly increase the time taken for shells to resolve binaries, I guess, but two paths are unlikely to have much impact, and I suspect some shells may be both deduplicating $PATH entries and building an internal hash of name -> binary path entries anyway.

@Gerschtli
Copy link
Contributor

As far as I can tell, this issue will be resolved as soon as my PR in nixpkgs gets merged into the release channel. So I think we can close this issue, as there is nothing more to do then waiting.

@Gerschtli
Copy link
Contributor

The fix is now available in nixos-19.03 channel. Issue can be closed.

@Gerschtli
Copy link
Contributor

@rycee @maralorn This issue can be closed :)

@maralorn
Copy link
Contributor Author

I don‘t have this problem anymore. But I changed my setup anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants