Skip to content

nix-env --query --available does not follow NIX_PATH #8784

@roberth

Description

@roberth

Describe the bug

My system does not have any channels.

I tried to use nix-index today, but it failed.

$ nix-index
+ querying available packages
error: querying available packages failed
caused by: nix-env failed with error: nix-env failed with exit code 1:
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

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

Taking the nix-env hint, I tried the following:

$ cd nixpkgs

$ NIX_PATH=nixpkgs=$PWD nix-env -qaP

ie no output

strace reveals that my nixpkgs checkout wasn't accessed at all.

Details
$ NIX_PATH=nixpkgs=$PWD strace nix-env -qaP 2>&1 | grep /home
newfstatat(AT_FDCWD, "/home/user", {st_mode=S_IFDIR|0700, st_size=6286, ...}, 0) = 0
newfstatat(AT_FDCWD, "/home/user/.nix-defexpr/channels", {st_mode=S_IFLNK|0777, st_size=44, ...}, AT_SYMLINK_NOFOLLOW) = 0
openat(AT_FDCWD, "/home/user/.nix-profile/etc/xdg/nix/nix.conf", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/user/.config/nix/nix.conf", O_RDONLY|O_CLOEXEC) = 3
newfstatat(AT_FDCWD, "/home/user/.nix-defexpr", {st_mode=S_IFDIR|0755, st_size=42, ...}, AT_SYMLINK_NOFOLLOW) = 0
newfstatat(AT_FDCWD, "/home/user/.nix-profile", {st_mode=S_IFLNK|0777, st_size=43, ...}, AT_SYMLINK_NOFOLLOW) = 0
readlink("/home/user/.nix-profile", "/nix/var/nix/profiles/per-user/u"..., 1024) = 43
newfstatat(AT_FDCWD, "/home/user/.nix-defexpr", {st_mode=S_IFDIR|0755, st_size=42, ...}, 0) = 0
newfstatat(AT_FDCWD, "/home/user/.nix-defexpr/default.nix", 0x7ffd0c005550, AT_SYMLINK_NOFOLLOW) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/home/user/.nix-defexpr", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
newfstatat(AT_FDCWD, "/home/user/.nix-defexpr/channels", 0x7ffd0c005590, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/home/user/.nix-defexpr/channels_root", 0x7ffd0c005590, 0) = -1 ENOENT (No such file or directory)

I've tried with a nix-defexpr

$ cat ~/.nix-defexpr/default.nix 
import <nixpkgs> {}

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

       at /home/user/.nix-defexpr/default.nix:1:8:

            1| import <nixpkgs> {}
             |        ^
            2|
(use '--show-trace' to show detailed location information)

Steps To Reproduce

  1. (optionally?) Configure NixOS with nix.channel.enable = false;
  2. Remove all channels
  3. Run nix-env with a NIX_PATH or -I.

Expected behavior

I can use nix-env and nix-index with just NIX_PATH and no channels on my system.

nix-env --version output

Additional context

Add any other context about the problem here.

Priorities

Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcliThe old and/or new command line interface

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions