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

Default Nix installations don't include user channels in NIX_PATH, causing inconsistent tool behavior #2033

Open
grahamc opened this issue Apr 1, 2018 · 19 comments
Assignees

Comments

@grahamc
Copy link
Member

@grahamc grahamc commented Apr 1, 2018

Should Nix installations include $HOME/.nix-defexpr/channels in the NIX_PATH? Should it appear before or after root channels?

nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels

$ nix-channel --list             
nixpkgsunstable https://nixos.org/channels/nixpkgs-unstable

$ nix-env -iA nixpkgsunstable.git
installing 'git-minimal-2.16.2'

$ nix-shell -p nixpkgsunstable.git
error: undefined variable 'nixpkgsunstable' at (string):1:94
(use '--show-trace' to show detailed location information)

$ nix-shell '<nixpkgsunstable>' -p git
error: file 'nixpkgsunstable' was not found in the Nix search path (add it using $NIX_PATH or -I), at (string):1:94
(use '--show-trace' to show detailed location information)

$ nix-build '<nixpkgsunstable>' -A git
error: file 'nixpkgsunstable' was not found in the Nix search path (add it using $NIX_PATH or -I)

vs:

$ export NIX_PATH=$NIX_PATH:$HOME/.nix-defexpr/channels

$ nix-env -iA nixpkgsunstable.git    
replacing old 'git-minimal-2.16.2'
installing 'git-minimal-2.16.2'

$ nix-shell -p nixpkgsunstable.git    
error: undefined variable 'nixpkgsunstable' at (string):1:94
(use '--show-trace' to show detailed location information)

$ nix-shell '<nixpkgsunstable>' -p git

[nix-shell:~]$ exit

$ nix-build '<nixpkgsunstable>' -A git
/nix/store/jaani1kx4a4kvz11d0myfkjjiiklfl7w-git-2.16.2

With this configuration, and the explicitly specified nixpkgs, is it possible for users to override nixpkgs without redefining the NIX_PATH? Does it matter?

@grahamc grahamc added bug Install bug UX question and removed bug labels Apr 1, 2018
@shlevy

This comment has been minimized.

Copy link
Member

@shlevy shlevy commented Apr 1, 2018

Yes, before root IMO.

@shlevy shlevy added the backlog label Apr 1, 2018
@shlevy shlevy self-assigned this Apr 1, 2018
@zimbatm

This comment has been minimized.

Copy link
Member

@zimbatm zimbatm commented Apr 1, 2018

Do you know why nix-env and nix-shell are not using the same lookup method?

For everything to be perfectly aligned, nix-channel --list should probably report all the channels on the NIX_PATH instead of using that fixed location.

@shlevy

This comment has been minimized.

Copy link
Member

@shlevy shlevy commented Apr 1, 2018

@zimbatm Mostly because nix-env is old 😀 It predates nix path.

@zimbatm

This comment has been minimized.

Copy link
Member

@zimbatm zimbatm commented Apr 1, 2018

I guess it's easier to fix the installer than nix-env :)

@shlevy shlevy assigned grahamc and unassigned shlevy Apr 1, 2018
@shlevy shlevy removed the backlog label Apr 1, 2018
@shlevy

This comment has been minimized.

Copy link
Member

@shlevy shlevy commented Apr 1, 2018

@grahamc Assigned to you, you pretty much own the install process these days 😀 Feel free to make a call on your own or call in @NixOS/nix-core as you see fit.

@grahamc

This comment has been minimized.

Copy link
Member Author

@grahamc grahamc commented Apr 1, 2018

I'm happy to implement these changes to the installer and what-not, but'd love input from @NixOS/nix-core too

@LnL7

This comment has been minimized.

Copy link
Member

@LnL7 LnL7 commented Apr 1, 2018

This isn't specific to the installer, it's this way to match the defaults from nixos. Also what is the plan for channels/user profiles with the new ui?

@grahamc

This comment has been minimized.

Copy link
Member Author

@grahamc grahamc commented Apr 1, 2018

I think we should also update NixOS to have user channels in the NIX_PATH for 18.03 and unstable, is that too big of a change to backport? (cc @vcunat, @fpletz)

@vcunat

This comment has been minimized.

Copy link
Member

@vcunat vcunat commented Apr 2, 2018

This kind of change seems good to me, if we do it before the official announcement. That would mean to do the change rather quickly now (and test it does what we want), within a couple days.

@grahamc grahamc mentioned this issue Apr 2, 2018
8 of 8 tasks complete
@FRidh

This comment has been minimized.

Copy link
Member

@FRidh FRidh commented Apr 3, 2018

@shlevy

Yes, before root IMO.

What is the motivation? Note the Nix docs on NIX_PATH don't explicitly mention what happens in case an entry is mentioned twice. Assuming one can override an entry (I've never tried), then administrators may prefer not to put user channels before root channels.

@shlevy

This comment has been minimized.

Copy link
Member

@shlevy shlevy commented Apr 3, 2018

@FRidh Earlier paths take precedence, and in general letting users override system-wide policy is the right call (outside of access control issues, of course)

@dtzWill

This comment has been minimized.

Copy link
Contributor

@dtzWill dtzWill commented Apr 3, 2018

Previously I believe I've seen Nix complain about multiple entiries-- I think when prepending "~/.nix-defexpr/channels" to NIX_PATH. Not sure if still happens, but just a heads-up.

@grahamc

This comment has been minimized.

Copy link
Member Author

@grahamc grahamc commented Apr 3, 2018

Yes, if in my user profile add nixos and my root profile has nixos it will warn, but work properly, on nix-env:

warning: name collision in input Nix expressions, skipping '/home/grahamc/.nix-defexpr/channels_root/nixos'

@jcrben

This comment has been minimized.

Copy link

@jcrben jcrben commented Jul 23, 2018

It seemed pretty easy to get into a position of being warned and a bit confusing to get out of it - wish I understood the purpose of adding channels_root to ~/.nix-defexpr/.

On my mac running 2.0.4, I ended up just removing all root channels to avoid the duplication - sudo -i su root and nix-channel --remove <name> worked even tho nix-channel --list was not working for root (I guess related to #1548)

@rycee

This comment has been minimized.

Copy link
Member

@rycee rycee commented Dec 16, 2018

It would be great to have $HOME/.nix-defexpr/channels in NIX_PATH by default. The new Home Manager installation instructions I put together relies on nix-channel --add https://blahblah home-manager which won't work out of the box on non-NixOS systems.

@mpickering

This comment has been minimized.

Copy link

@mpickering mpickering commented Jan 22, 2019

This broke my configuration and the commit message gives no indication about how to fix it. What is the proper way to stop this behaviour?

@edolstra

This comment has been minimized.

Copy link
Member

@edolstra edolstra commented Jan 22, 2019

@mpickering What commit are you referring to?

@mpickering

This comment has been minimized.

Copy link

@mpickering mpickering commented Jan 22, 2019

8ab8d9cb74e75de46e647a5d77c137f7ef3ebd2b

I think I should fix it by removing all channels?

@masaeedu

This comment has been minimized.

Copy link
Contributor

@masaeedu masaeedu commented Aug 30, 2019

Could someone explain the purpose of every user having:

NIX_PATH=nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixpkgs:/nix/var/nix/profiles/per-user/root/channels

as set up by the /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh script in a multi-user non-NixOS install? Shouldn't the user just be adding/upgrading/using their own channels?

The problem right now is that if the user additionally sources ~/.nix-profile/etc/profile.d/nix.sh, there's a good chance the nixpkgs channel definition will be duplicated (so they'll always get that warning, which I only understand now after several hours looking through the various shell scripts and Github issues). If they source it after the /etc/profile.d stuff (which is likely), their duplicate channel definitions lose.

Would anything break if the root channels were only added to NIX_PATH for the root user?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.