FS#78507 - [nix] NIX_PATH is set to the wrong value

Attached to Project: Community Packages
Opened by Loïc Damien (dzamlo) - Saturday, 13 May 2023, 14:54 GMT
Last edited by Toolybird (Toolybird) - Monday, 19 June 2023, 05:52 GMT
Task Type Bug Report
Category Packages
Status Closed
Assigned To Caleb Maclennan (alerque)
George Rawlinson (rawlinsong)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 1
Private No

Details

Description:

The nix package includes the file "/usr/lib/environment.d/nix-daemon.conf" which set the environment variable NIX_PATH to include "/nix/var/nix/profiles/per-user/$USER/channels". But this directory doesn't exist even after following instructions from the wiki and the nix documentation. The correct directory is "$HOME/.local/state/nix/profiles/channels". But the simplest fix is to not set this variable, nix will find the correct directory by itself if NIX_PATH is unset.

Additional info:
* package version(s): nix 2.15.0-2

Steps to reproduce:
1. Install the nix package
2. Add your user to the nix-users group
3. Enable nix-daemon.service
4. Reboot
5. Add the nixpkgs channel:
$ nix-channel --add https://nixos.org/channels/nixpkgs-unstable
$ nix-channel --update
6. Try to run nix-shell (this is the command that fails):
$ nix-shell -p hello

Steps to fix:
Unset NIX_PATH by removing it from "/usr/lib/environment.d/nix-daemon.conf" or using unset.
This task depends upon

Closed by  Toolybird (Toolybird)
Monday, 19 June 2023, 05:52 GMT
Reason for closing:  Works for me
Additional comments about closing:  See comments
Comment by Toolybird (Toolybird) - Sunday, 14 May 2023, 00:37 GMT
> 6. Try to run nix-shell (this is the command that fails):
> $ nix-shell -p hello

What fails? I followed your steps and saw no errors i.e. cannot repro. Not sure where it's going wrong for you. Did you forget to install the hello pkg as per the wiki?:

$ nix-env -iA nixpkgs.hello
Comment by Loïc Damien (dzamlo) - Sunday, 14 May 2023, 19:38 GMT
I installed the hello pkg, but that shouldn't be necessary, nix should install it if needed when you run nix-shell.

If I add the $HOME/.local/state/nix/profiles/channels path to the search path, either with the -I argument or adding it to NIX_PATH, it works. If I clear NIX_PATH it works too.

I get the following output:
$ nix-shell -p hello
warning: Nix search path entry '/nix/var/nix/profiles/per-user/loicdamien/channels/nixpkgs' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/loicdamien/channels' 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 = [ (hello) ]; } ""
| ^

(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)
Comment by Caleb Maclennan (alerque) - Wednesday, 17 May 2023, 13:05 GMT
I am also unable to replicate this issue. I also *do* have that path on all the machines I've been running `nix` on, so it seems like this is getting created by *something*.

Finally, the messages your are showing are warnings, not errors. Hence I think something else is wrong here.
Comment by Loïc Damien (dzamlo) - Friday, 19 May 2023, 09:48 GMT
> Finally, the messages your are showing are warnings, not errors. Hence I think something else is wrong here.
It starts with two warnings, but then there is an error. And the error is due to this problem with NIX_PATH because if I fix it (adding the path in my home to NIX_PATH, adding it with the -I argument or unsetting NIX_PATH and thus using the default path which include the path in the home directory) it works.

> I also *do* have that path on all the machines I've been running `nix` on, so it seems like this is getting created by *something*
For some reason, it isn't created on my machine. So it seems that the error is unique to my machine then. I guess we can close this bug then ?

Loading...