-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Set nixpkgs= in nix-profile.sh #3130
Set nixpkgs= in nix-profile.sh #3130
Conversation
Setting nixpkgs is necessary for the new commands to resolve. Related issues: - NixOS#3119 - NixOS#1892 - NixOS#1865
I don't see why this is needed. If |
export NIX_PATH=${NIX_PATH:+$NIX_PATH:}$HOME/.nix-defexpr/channels | ||
# Append ~/.nix-defexpr/channels/nixpkgs to $NIX_PATH so that | ||
# <nixpkgs> paths work when the user has fetched the Nixpkgs channel. | ||
export NIX_PATH="${NIX_PATH:+$NIX_PATH:}nixpkgs=$HOME/.nix-defexpr/channels/nixpkgs:$HOME/.nix-defexpr/channels" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Analysis
Nix scans all the entries and picks the first matching one. A match is just a check that there is a file or directory.
Eg:
$ mkdir -p foo/nixpkgs
$ NIX_PATH=./foo:nixpkgs=/proc nix-instantiate --eval --expr '<nixpkgs>'
/home/zimbatm/foo/nixpkgs
Now if I remove ./foo/nixpkgs
:
$ rmdir foo/nixpkgs
$ NIX_PATH=./foo:nixpkgs=/proc nix-instantiate --eval --expr '<nixpkgs>'
/home/zimbatm/foo/nixpkgs
/proc
Another important thing is that if there are two nixpkgs
entries, it will try them in order but also complain if the first entry doesn't match:
$ NIX_PATH=nixpkgs=/doesnt/exist:nixpkgs=/proc nix-instantiate --eval --expr '<nixpkgs>'
warning: Nix search path entry '/doesnt/exist' does not exist, ignoring
/proc
Conclusion
The issue with the old implementation is that the user's channel is not picked up if NIX_PATH already points to an existing nixpkgs. This can be fixed by changing the ordering instead:
export NIX_PATH="${NIX_PATH:+$NIX_PATH:}nixpkgs=$HOME/.nix-defexpr/channels/nixpkgs:$HOME/.nix-defexpr/channels" | |
export NIX_PATH="$HOME/.nix-defexpr/channels${NIX_PATH:+:$NIX_PATH}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot that Eelco wanted to move away from the naked directory entries in NIX_PATH. Maybe nix search
has a different resolution algorithm. But I don't see how to take a layered approach where the user can override the system channel, without using the naked directories. Otherwise we'll be in the situation where an error pops-up all the time for the users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't really matter long-term since on the flakes branch, a command like nix build nixpkgs#hello
searches the registry rather than NIX_PATH
or channels. The temporary fix I just committed is to recognize channel directories generated by nix-channel
and add each subdirectory to the default expression.
I've gone for a different fix (adding all channel directories) in e6e61f0. |
Setting nixpkgs is necessary for the new commands to resolve. Otherwise things like
nix search
do not work in a new install.Related issues:
nix search
never finds any packages #1892Also see discussion in b6eb8a2#diff-5bffa5f8b1fe4444a3db1c0f9f8a7a47
and in nix-darwin/nix-darwin#140