NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.15k stars 1.47k forks source link

Nix programs keep saying `warning: Nix search path entry ...` #2982

Open kindaro opened 5 years ago

kindaro commented 5 years ago

Issue description

I installed Nix — multi-user, I think. (I don't exactly understand what it means.) I am logged in as non-root user, but the Nix programs I use, specifically nix-channel, nix-env, nix-shell, keep saying this:

warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring

— Every time, sometimes several times in a row.

If I create this directory, and also nixpkgs in it, another problem appears:

error: opening file '/nix/var/nix/profiles/per-user/root/channels/nixpkgs/default.nix': No such file or directory

If I create this file, it still doesn't work:

error: syntax error, unexpected $end, at /nix/var/nix/profiles/per-user/root/channels/nixpkgs/default.nix:1:1

I don't understand what reason is there for these programs to even try access something that belongs to another user.

Steps to reproduce

I installed Nix on Arch Linux from AUR, and then ran archlinux-nix because otherwise it doesn't work.

% sudo aura -A nix  # Aura is an AUR helper. It just installs packages from AUR, nothing more.
% sudo archlinux-nix setup-build-group
% sudo archlinux-nix install-sandbox
% sudo archlinux-nix enable-nix-daemon

Now, anything I do, I receive this warning.

Technical details

% nix-shell -p nix-info --run "nix-info -m"
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixpkgs' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixpkgs' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
 - system: `"x86_64-linux"`
 - host os: `Linux 5.1.16-arch1-1-ARCH, Arch Linux, noversion`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.2.2`
 - channels(kindaro): `"nixpkgs-19.09pre184803.d567c486ca5"`
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixpkgs' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
 - nixpkgs: `/home/kindaro/.nix-defexpr/channels/nixpkgs`
dirn commented 5 years ago

I'm experiencing the same problem on a single user installation on macOS.

$ nix-shell -p nix-info --run "nix-info -m"
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
 - system: `"x86_64-darwin"`
 - host os: `Darwin 18.6.0, macOS 10.14.5`
 - multi-user?: `no`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.2.2`
 - channels(dirn): `"darwin, nixpkgs-19.09pre186574.88d9f776091"`
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
 - nixpkgs: `/Users/dirn/.nix-defexpr/channels/nixpkgs`

I see that the path is included in my $NIX_PATH, but I'm not sure how it got there.

$ echo $NIX_PATH
darwin-config=/Users/dirn/.nixpkgs/darwin-configuration.nix /nix/var/nix/profiles/per-user/root/channels /Users/dirn/.nix-defexpr/channels
matthewbauer commented 4 years ago

It looks like the archlinux-nix installer is not setting up channels correctly. To add the root channel , you should do:

sudo -i nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs
sudo -i nix-channel --update nixpkgs
matthewbauer commented 4 years ago

I'm experiencing the same problem on a single user installation on macOS.

$ nix-shell -p nix-info --run "nix-info -m"
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
 - system: `"x86_64-darwin"`
 - host os: `Darwin 18.6.0, macOS 10.14.5`
 - multi-user?: `no`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.2.2`
 - channels(dirn): `"darwin, nixpkgs-19.09pre186574.88d9f776091"`
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
 - nixpkgs: `/Users/dirn/.nix-defexpr/channels/nixpkgs`

I see that the path is included in my $NIX_PATH, but I'm not sure how it got there.

$ echo $NIX_PATH
darwin-config=/Users/dirn/.nixpkgs/darwin-configuration.nix /nix/var/nix/profiles/per-user/root/channels /Users/dirn/.nix-defexpr/channels

I think you should report this in nix-darwin issue tracker. I think the profile should not be setting up a root channel here:

https://github.com/LnL7/nix-darwin/blob/master/pkgs/darwin-installer/default.nix#L9

/cc @grahamc @LnL7

kindaro commented 4 years ago

@matthewbauer This seems to work. Thank you.

ldeck commented 4 years ago

I'm experiencing the same problem on a single user installation on macOS. ... I see that the path is included in my $NIX_PATH, but I'm not sure how it got there.

Yes, same here. I’m not sure what triggered this inclusion either.

I tried a workaround of creating the relevant paths:

sudo mkdir -p /nix/var/nix/profiles/per-user/root/channels

But that only reduces some warnings. If creating the channels/nixpkgs path then it requires a default.nix file to exist.

It seems the workaround is to specifically re-export NIX_PATH in your ~/.profile

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

Otherwise, the following warnings get very noisy.

ldeck@ldeck ~ % nix-shell -p nix-info --run "nix-info -m"               
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixpkgs' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixpkgs' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
 - system: `"x86_64-darwin"`
 - host os: `Darwin 19.2.0, macOS 10.15.2`
 - multi-user?: `no`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.3.1`
 - channels(ldeck): `"nixpkgs-20.03pre204216.cc6cf0a96a6"`
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixpkgs' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
 - nixpkgs: `/Users/ldeck/.nix-defexpr/channels/nixpkgs`
drewboardman commented 4 years ago

Is there any update on this? I'm seeing the same thing:

https://github.com/NixOS/nixpkgs/issues/78714

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

siraben commented 3 years ago

Still relevant to me.

iFreilicht commented 3 years ago

I have the same issue. After running the commands @matthewbauer recommended, I get different errors:

$ sudo -i  nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs
$ sudo -i nix-channel --update nixpkgs
warning: the group 'nixbld' specified in 'build-users-group' does not exist
unpacking channels...
warning: the group 'nixbld' specified in 'build-users-group' does not exist
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
$ nix-env -i hello
warning: name collision in input Nix expressions, skipping '/home/felix/.nix-defexpr/channels_root/nixpkgs'

My quick fix for this was rm .nix-defexpr/channels_root, but I was a bit worried this could break something down the line.

So, the full fix was to wipe nix completely and re-install it as a multi-user installation. The installer unfortunately still detected traces of nix, even after I removed it completely, so I installed like this:

sudo rm -rf /etc/nix /nix /root/.nix-profile /root/.nix-defexpr /root/.nix-channels
rm -rf ~/.nix-profile ~/.nix-defexpr ~/.nix-channels
ALLOW_PREEXISTING_INSTALLATION=1 sh <(curl -L https://nixos.org/nix/install) --daemon

And now everything is working perfectly!

sebastiant commented 3 years ago

Got fed up with these warnings in my single-user installed nix-darwin. Awaiting the https://github.com/LnL7/nix-darwin/issues/295 to be attended here's a very easy workaround: We'll remove the channel, set up a local nix-darwin repository and use it instead.

Clone nix-darwin and set NIX_PATH to use the local repository instead of the channel:

$ git clone git@github.com:LnL7/nix-darwin.git ~/.nix-defexpr/darwin
$ export NIX_PATH=darwin=$HOME/.nix-defexpr/darwin:darwin-config=$HOME/.nixpkgs/darwin-configuration.nix:$NIX_PATH
$ nix-channel --remove darwin

Now, edit your darwin-configuration.nix and add nix.nixPath = [ "darwin=/Users/<you>/.nix-defexpr/darwin" ];

Now, let's fix the issue: $ cd ~/.nix-defexpr/darwin remove the occurrences of "/nix/var/nix/profiles/per-user/root/channels" in the just cloned repository. The files are modules/nix/default.nix and pkgs/darwin-installer/default.nix.

Build and switch using the local repository: $ darwin-rebuild switch -I darwin=.

Done

What we've done is all described in the manual https://daiderd.com/nix-darwin/ under the sections "Manual Install" and "Contributing"

chrissound commented 2 years ago

Happened to me randomnly though I did add a channel earlier today via:

sudo nix-channel --add https://nixos.org/channels/nixos-21.11 nixos-2111
sudo nix-channel --update nixos-2111

Fixed via: sudo nix-channel --update nixos

This is on a native nixos system. nixos-version 20.09.4393.068984c00e0 (Nightingale)

takedawilliam commented 2 years ago

Happened to me randomnly though I did add a channel earlier today via:

sudo nix-channel --add https://nixos.org/channels/nixos-21.11 nixos-2111
sudo nix-channel --update nixos-2111

Fixed via: sudo nix-channel --update nixos

This is on a native nixos system. nixos-version 20.09.4393.068984c00e0 (Nightingale)

On MacOS, I need to run sudo nix-channel --update nixpkgs instead

luisnquin commented 2 years ago

It looks like the archlinux-nix installer is not setting up channels correctly. To add the root channel , you should do:

sudo -i nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs
sudo -i nix-channel --update nixpkgs

Thank youuuu <3

It works in NixOS 22.11 x86_64

nixos-discourse commented 2 years ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nix-shell-two-machines-different-results/21323/9

fdendorfer commented 1 year ago

Just leaving this here for others and in case I forget:

If you have have installed Nix via the script with sudo, you have to run nix-env, nix-shell, etc. with sudo as well, otherwise you also get the error "Nix search path entry '/nix/var/nix/profiles/per-user/your-username/channels' does not exist"

iFreilicht commented 1 year ago

@fdendorfer This is the case for a single-user install, yes. Is that how you installed nix? The multi-user installer shouldn't be run with sudo (I'm not even sure it's possible), it will use sudo automatically for the relevant commands.

AkechiShiro commented 1 year ago

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

I installed nix using apt.

Just hit this issue on debian 11, the fix was export your NIX_PATH, thanks to @ldeck Wish this was documented somewhere, I might open a new issue for this

fishy commented 8 months ago

I'm getting a similar issue but not for root but my own user:

$ nix-shell -p nix-info --run "nix-info -m"
warning: Nix search path entry '/nix/var/nix/profiles/per-user/fishy/channels/nixpkgs' does not exist, ignoring
error:
       … <borked>

         at «none»:0: (source not available)

       … while calling the 'import' builtin

         at «string»:1:18:

            1| {...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [ (nix-info) ]; } ""
             |                  ^

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

       at «none»:0: (source not available)

it's indeed not under /nix/var/nix/profiles/per-user/fishy/channels/ (which is empty):

$ ls -l /nix/var/nix/profiles/per-user/fishy/channels/
total 0

but I have been using it fine, somehow?

$ nix-channel --list
nixpkgs https://nixos.org/channels/nixpkgs-unstable
$ nix-channel --update nixpkgs
unpacking channels...
$ echo $NIX_PATH
nixpkgs=/nix/var/nix/profiles/per-user/fishy/channels/nixpkgs:/nix/var/nix/profiles/per-user/fishy/channels

so my nixpkgs channel was added in a weird way?

mjarosie commented 5 months ago

What fixed it for me was just running: sudo -i nix-channel --update nixpkgs, even without adding the unstable channel explicitly.

GNRSN commented 3 weeks ago

Also getting this warning after fresh Nix installer installation followed by nix-darwin installation.

Multi user installation here though

iFreilicht commented 3 weeks ago

@GNRSN The determinate installer is maintained here and is not official (though most people recommend it over the official installer for good reason), so if this was an issue with that installer, it would have to be reported there.

However, this seems to be an issue with nix-darwin as others have already pointed out, and nix-darwin does indeed have an open issue for this: https://github.com/LnL7/nix-darwin/issues/145

Apparently this can't really be fixed in nix-darwin itself due to compatibility with an existing installation, but you can fix it on your machine by adding

  nix.nixPath = pkgs.lib.mkForce [{
    darwin-config = builtins.concatStringsSep ":" [
      "$HOME/.nixpkgs/darwin-configuration.nix"
      "$HOME/.nix-defexpr/channels"
    ];
  }];

to your configuration as per this comment.

Swoorup commented 2 weeks ago

@GNRSN The determinate installer is maintained here and is not official (though most people recommend it over the official installer for good reason), so if this was an issue with that installer, it would have to be reported there.

However, this seems to be an issue with nix-darwin as others have already pointed out, and nix-darwin does indeed have an open issue for this: LnL7/nix-darwin#145

Apparently this can't really be fixed in nix-darwin itself due to compatibility with an existing installation, but you can fix it on your machine by adding

  nix.nixPath = pkgs.lib.mkForce [{
    darwin-config = builtins.concatStringsSep ":" [
      "$HOME/.nixpkgs/darwin-configuration.nix"
      "$HOME/.nix-defexpr/channels"
    ];
  }];

to your configuration as per this comment.

That didn't fix my issue. I do run the determinate version of nix-darwin. The comment here fixed by issue though, since I was using flakes: https://discourse.nixos.org/t/how-to-resolve-nixpkgs-was-not-found-error-without-channels/47258