nakato / nixos-bpir3-example

MIT License
24 stars 5 forks source link

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

Closed ghostbuster91 closed 1 year ago

ghostbuster91 commented 1 year ago

Hi,

Whenever I try to use nix-index or nix-shell and such I am getting following error:

❯ nix-index                                                                                                           22:57:14
+ querying available packages
error: querying available packages failed
caused by: nix-env failed with error: nix-env failed with exit code 1:
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixos' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

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

Which is presumably because the NIX_PATH environment variable is not set. I guess that the reason why it is not set is that the nixos was never "installed" but rather we are running an "installation disk"(?).

Do you know how that could be fixed?

My desktop nixos reports:

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

However these paths do not exist on the bananpi nixos.

nakato commented 1 year ago

Which is presumably because the NIX_PATH environment variable is not set.

I don't think these paths would be checked if the environment variable was not set. It looks like they're set by PAM from /etc/pam/environment

Do you know how that could be fixed?

It looks like the channel is defined

[root@bpir3:~]# nix-channel --list
nixos https://nixos.org/channels/nixos-unstable

After I run the following it populates

[root@bpir3:~]# nix-info 
system: "aarch64-linux", multi-user?: no, version: nix-env (Nix) 2.13.3, nixpkgs: not found

[root@bpir3:~]# nix-channel --update
unpacking channels...

[root@bpir3:~]# nix-info 
system: "aarch64-linux", multi-user?: yes, version: nix-env (Nix) 2.13.3, channels(root): "nixos", nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos

Looking into it, it looks like it's normally pre-populated on "installation media" via <nixpkgs>/nixos/modules/installer/cd-dvd/channel.nix. It's not very obvious, but it looks like that is intended to be included in "golden images" as well, and it takes care of doing a one-time command at boot to set it up to a copy of nixpkgs in the nix-store included in the filesystem.

This was an interesting one, it looks like I never ran into this one because I manage the device entirely via nix-command (nix shell instead of nix-shell) and flakes, and my in-service router still doesn't have those channel links.

ghostbuster91 commented 1 year ago

Thanks for the explanation, updating channel information fixed the issue :+1: