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

Set nixpkgs= in nix-profile.sh #3130

Closed

Conversation

matthewbauer
Copy link
Member

@matthewbauer matthewbauer commented Oct 9, 2019

Setting nixpkgs is necessary for the new commands to resolve. Otherwise things like nix search do not work in a new install.

Related issues:

Also see discussion in b6eb8a2#diff-5bffa5f8b1fe4444a3db1c0f9f8a7a47

and in LnL7/nix-darwin#140

Setting nixpkgs is necessary for the new commands to resolve.

Related issues:

- NixOS#3119
- NixOS#1892
- NixOS#1865
@edolstra
Copy link
Member

edolstra commented Oct 9, 2019

I don't see why this is needed. If ~/.nix-defexpr/channels contains a nixpkgs subdirectory, then <nixpkgs> should resolve to that without any special hacks.

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"
Copy link
Member

@zimbatm zimbatm Oct 9, 2019

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:

Suggested change
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}"

Copy link
Member

@zimbatm zimbatm Oct 9, 2019

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.

Copy link
Member

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.

@edolstra
Copy link
Member

edolstra commented Oct 9, 2019

I've gone for a different fix (adding all channel directories) in e6e61f0.

@edolstra edolstra closed this Oct 9, 2019
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 this pull request may close these issues.

None yet

3 participants