Try running the following with Nix 2.0:
$ NIX_PATH=/nix/var/nix/profiles/per-user/root/channels nix run nixpkgs.hello
error: attribute 'nixpkgs' in selection path 'nixpkgs.hello' not found
This is different than how previous version of Nix worked.
Oddly settings 'nixpkgs' to anything in NIX_PATH (even something that doesn't exist) will fix this issue:
NIX_PATH='nixpkgs=asdf:/nix/var/nix/profiles/per-user/root/channels' nix run nixpkgs.hello
@edolstra Should this be supported? If not we need to update nix-profile.sh.in because it's using it:
https://github.com/NixOS/nix/blob/master/scripts/nix-profile-daemon.sh.in#L53
This should be supported, because the manual still documents NIX_PATH as working this way (see Chapter 17).
This is definitely a bug, not an intentional change. Will look into it.
No, it's not a bug. Rather, the nix command does not have a replacement for channels yet, so it's currently left undefined where it gets its inputs from. (This is one of the main reasons why the nix CLI is marked experimental.) So currently it only uses prefixed NIX_PATH elements like nixpkgs=....
@edolstra IMO it's definitely a bug at least that it works with a dummy nixpkgs= argument... #1942 fixes it too.
How is it not a bug that the nix command is broken on a fresh install of Nix 2.0?
How is it not a bug that the nix command is broken on a fresh install of Nix 2.0?
It also could be a bug in nix-profile-daemon.sh (which is only used by MacOS currently). See #1664 for a potential fix.
Right, the Linux install script sets nixpkgs=$HOME/.nix-defexpr/channels/nixpkgs.
Is there a concern with #1942?
So currently it only uses prefixed NIX_PATH elements like nixpkgs=....
Has this behaviour changed?
@grahamc has tested NIX_PATH behaviour,
$ NIX_PATH=/home/grahamc/.nix-defexpr/channels nix build -f '<nixpkgs>' git
$ ls -la result
lrwxrwxrwx 1 grahamc users 54 Apr 3 08:32 result -> /nix/store/jaani1kx4a4kvz11d0myfkjjiiklfl7w-git-2.16.2
and it seems like the unprefixed NIX_PATH=/home/grahamc/.nix-defexpr/channels is still being used for evaluation?
Is nix build actually a new command or is that just an alias for nix-build? Because the issue seems to be the new nix command stuff treats NIX_PATH differently than the existing commands, but if nix build is just an alias for nix-build then it stands to reason that you wouldn't see this issue with it.
This is a major pain on macOS, which does not have a prefixed NIX_PATH, and only has the root channels by default. Same issue with the --daemon installation on Linux.
It depends on the content of the NIX_PATH target folder:
$ ls /nix/var/nix/profiles/per-user/root/channels
binary-caches manifest.nix nixos
When NIX_PATH is just a path it will look up thinks from that folder. So in that case the channel doesn't contain nixpkgs and it will fail.
$ NIX_PATH=/nix/var/nix/profiles/per-user/root/channels nix repl
Welcome to Nix version 2.1.1. Type :? for help.
nix-repl> import <manifest.nix>
[ 芦derivation ???禄 ]
nix-repl> import <nixos>
芦lambda @ /nix/store/syxm6jgcc0wj2qc7pg6vz44d5s9a42nc-nixos-18.09.1023.06fb0253afa/nixos/pkgs/top-level/impure.nix:15:1禄
nix-repl> import <nixpath>
error: file 'nixpath' was not found in the Nix search path (add it using $NIX_PATH or -I), at (string):1:8
fixed in d7a84d330cc677d3c9e2c5553a861ab9f82245f6
Not fixed actually
Definitely broken. Updating to Nix 2.3 just broke nix run for me, since I'm not customizing my NIX_PATH.
Quick hacky workaround that seems to be working for me on a Mac, based on @edolstra's comment above, is to prefix the command with NIX_PATH=nixpkgs=$NIX_PATH/nixpkgs, as shown below:
$ nix run nixpkgs.hello
error: attribute 'nixpkgs' in selection path 'nixpkgs.hello' not found
$ NIX_PATH=nixpkgs=$NIX_PATH/nixpkgs nix run nixpkgs.hello
[1 copied (0.1 MiB), 0.0 MiB DL]
bash-3.2$ exit
Seems to also fix nix search and nix eval.
Question to more knowledgeable people: should I put this NIX_PATH adjustment in my ~/.profile or something?
Yes, put it in your ~/.profile after sourcing the setup script, except I would write nixpkgs=$HOME/.nix-defexpr/channels/nixpkgs rather than nixpkgs-$NIX_PATH/nixpkgs in case NIX_PATH changes again to include something else.
Personally, I tweaked my profile to make sure NIX_PATH didn't have the string nixpkgs= in it first, before prepending the new path onto it.
:/ This is still an issue with the recommended install method on Ubuntu.
$ curl https://nixos.org/nix/install | sh
$ . ~/.nix-profile/etc/profile.d/nix.sh
$ nix build nixpkgs.hello
error: attribute 'nixpkgs' in selection path 'nixpkgs.hello' not found
Are there plans for a release incorporating this fix anytime soon?
@t184256 Nix 2.3.1 was released the day after that commit, and includes the fix. It might not have been in nixpkgs when you posted, but it's definitely in the current nixpkgs-unstable.
I've asked because I had to work around in on 2.3.1 specifically (taken from the aarch64 tarball).
Oh, weird. 2.3.1 made it work fine for me after removing the workaround.
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/file-nixpkgs-was-not-found-in-the-nix-search-path/10433/1
Most helpful comment
This is a major pain on macOS, which does not have a prefixed NIX_PATH, and only has the root channels by default. Same issue with the
--daemoninstallation on Linux.