"nix search" duplicate results in brand-new NixOS install. How to fix?

This other issue is already marked as solved, so I thought I’d open a new one.

As detailed in the comment at Duplicate results in `nix search` - #5 by trusktr, I made my first NixOS install and ran into the problem, and I’m not sure if the commands I listed are what caused it.

But now I have completed a brand new second install just to be sure I am doing it right, and this time I’m following the manual exactly so to avoid any possibility that I deviated and caused the issue.

Now, after installing Nix onto my chosen disk, I am still having the issue.

Once I logged into the new Nix OS, I ran the following as root, which shows duplicate packages:

[trusktr@starnix:~]$ nix search tweak-tool
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: no results for the given search term(s)!

[trusktr@starnix:~]$ sudo bash

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for trusktr: 

[root@starnix:/home/trusktr]# nix-channel --list
nixos https://nixos.org/channels/nixos-19.09

[root@starnix:/home/trusktr]# nix search tweak-tool
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: no results for the given search term(s)!

[root@starnix:/home/trusktr]# nix-channel --update
unpacking channels...
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
created 1 symlinks in user environment

[root@starnix:/home/trusktr]# nix-channel --update
unpacking channels...

[root@starnix:/home/trusktr]# nix search tweak-tool
warning: using cached results; pass '-u' to update the cache
error: no results for the given search term(s)!

[root@starnix:/home/trusktr]# nix search -u tweak-tool
* nixos.gnome3.gnome-tweak-tool (gnome-tweaks-3.32.0)
  A tool to customize advanced GNOME 3 options

* nixpkgs.gnome3.gnome-tweak-tool (gnome-tweaks-3.32.0)
  A tool to customize advanced GNOME 3 options


[root@starnix:/home/trusktr]# nix search tweak-tool
warning: using cached results; pass '-u' to update the cache
* nixos.gnome3.gnome-tweak-tool (gnome-tweaks-3.32.0)
  A tool to customize advanced GNOME 3 options

* nixpkgs.gnome3.gnome-tweak-tool (gnome-tweaks-3.32.0)
  A tool to customize advanced GNOME 3 options


[root@starnix:/home/trusktr]# nix-channel --list
nixos https://nixos.org/channels/nixos-19.09

Why do I have duplicate results from both nixos and nixpkgs although nix-channel --list shows only one channel? I’m completely new to NixOS, so I have no clue why there are duplicate results.

When I was following the steps in 2.5.4. Installing from another Linux distribution, the search results from my Ubuntu instance did not have duplicates. I only see duplicates when I search from inside my new Nix install.

I see that

# echo $NIX_PATH

shows something similar to @jonringer’s comment:

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

It looks just about the same, except for his user-specific prefix. Are duplicate results simply expected? I am thinking that I did something wrong, and that having duplicate results is something that a more advanced user would have if they enable multiple channels, which as a new user was not trying to do.

it will show “duplicates” because it’s picking up more than one channel. It could be that your nixos channel is stable, and your nixpkgs channel is unstable. In which you could get packages of different version from them.

1 Like

I think I only have one channel:

# nix-channel --list
nixos https://nixos.org/channels/nixos-19.09

Do you by any chance have system-wide channels, owned by the root user ?

sudo nix-channel --list

I meant to use the # to indicate it was root. Here’s with sudo:

$ sudo nix-channel --list
[sudo] password for trusktr: 
nixos https://nixos.org/channels/nixos-19.09

Conversely, do you have user-local channels then :wink:

$ nix-channel --list
$ nix-channel --list
# no output

When I followed the steps in 2.5.4, after I booted into my new Gnome desktop, I logged in as root, created a password for my normal user, then while logged in as root I ran the commands I posted above, which showed the duplicate results. Basically I haven’t done anything on this new system other than that.

Your search results are not exactly duplicated. You have two sources of packages, nixpkgs and nixos.

See the difference between these ?

nixos.gnome3.gnome-tweak-tool
nixpkgs.gnome3.gnome-tweak-tool

Now, on my system, despite having roughly the same config, I only see one result in nix search. I am a bit out of ideas to help you here.

I’m totally new to Nix. I followed the steps in 2.5.4. Installing from another Linux distribution, and when I boot into the brand new Nix install that’s what nix search shows (the results from two channels).

Basically this is what I did. From Ubuntu that I booted into from a thumb drive:

$ curl https://nixos.org/nix/install | sh
$ . $HOME/.nix-profile/etc/profile.d/nix.sh
$ nix-channel --list
nixpkgs https://nixos.org/channels/nixpkgs-unstable
$ nix-channel --add https://nixos.org/channels/nixos-19.09 nixpkgs
$ nix-channel --update
$ nix-env -iE "_: with import <nixpkgs/nixos> { configuration = {}; }; with config.system.build; [ nixos-generate-config nixos-install nixos-enter manual.manpages ]"

Then after mounting the partitions from my target disk,

$ sudo `which nixos-generate-config` --root /mnt
$ sudo groupadd -g 30000 nixbld
$ sudo useradd -u 30000 -g nixbld -G nixbld nixbld

And then after editing the /mnt/etc/nixos/configuration.nix file to add programs that I need,

$ sudo PATH="$PATH" NIX_PATH="$NIX_PATH" `which nixos-install` --root /mnt

Finally, I rebooted into the new Nix OS, and then sudo nix search <anything> shows the results from both channels.

Do any steps there create both channels on the target?

Could you check your nix-defexpr ? And give a look at the documentation at Introduction - Nix Reference Manual if you want to know more ?

Mine has

$ tree ~/.nix-defexpr 
/home/gmaudoux/.nix-defexpr
└── channels_root -> /nix/var/nix/profiles/per-user/root/channels

I guess yours could have two entries. I have no idea what this does, except that it is precisely linked to the behavior of these top-level nixos and nixpkgs attributes in some cases.

If you have two entries, it should be safe to keep only the channels_root to fall back to a “proper” nixos distribution setup.

Here’s what I see:

[trusktr@starnix:~]$ tree ~/.nix-defexpr
The program ‘tree’ is currently not installed. You can install it by typing:
  nix-env -iA nixos.tree

[trusktr@starnix:~]$ ll ~/.nix-defexpr
ls: cannot access '/home/trusktr/.nix-defexpr': No such file or directory

[trusktr@starnix:~]$ sudo bash
[sudo] password for trusktr: 

[root@starnix:/home/trusktr]# ll ~/.nix-defexpr
total 0
lrwxrwxrwx 1 root root 44 Jan  6 23:46 channels -> /nix/var/nix/profiles/per-user/root/channels

[root@starnix:/home/trusktr]# ll /nix/var/nix/profiles/per-user/root/channels
lrwxrwxrwx 1 root root 15 Jan  6 23:46 /nix/var/nix/profiles/per-user/root/channels -> channels-1-link

[root@starnix:/home/trusktr]# ll /nix/var/nix/profiles/per-user/root/channels-1-link
lrwxrwxrwx 1 root root 60 Jan  6 23:46 /nix/var/nix/profiles/per-user/root/channels-1-link -> /nix/store/b5x66dl1arb9s8brrk4lsgysmwny4nd6-user-environment

[root@starnix:/home/trusktr]# ll /nix/store/b5x66dl1arb9s8brrk4lsgysmwny4nd6-user-environment
total 8
lrwxrwxrwx 1 root root 60 Dec 31  1969 manifest.nix -> /nix/store/ybia58aj8cmyacpzd58ysdy9y0bd961k-env-manifest.nix
lrwxrwxrwx 1 root root 78 Dec 31  1969 nixos -> /nix/store/8v0n7zn9hpmqays85zwibyfivr4ddyy4-nixos-19.09.1778.db3e8325a9b/nixos

I edited the above, had a mistake

Seems like there is only one channel there.

Aha! Now see this:

[root@starnix:/home/trusktr]# ll /nix/store/8v0n7zn9hpmqays85zwibyfivr4ddyy4-nixos-19.09.1778.db3e8325a9b/nixos
total 3592
-r--r--r--  1 root root    1097 Dec 31  1969 COPYING
-r--r--r--  1 root root     968 Dec 31  1969 default.nix
dr-xr-xr-x  8 root root    4096 Dec 31  1969 doc
dr-xr-xr-x  4 root root    4096 Dec 31  1969 lib
dr-xr-xr-x  3 root root    4096 Dec 31  1969 maintainers
dr-xr-xr-x  7 root root    4096 Dec 31  1969 nixos
lrwxrwxrwx  1 root root       1 Dec 31  1969 nixpkgs -> .
dr-xr-xr-x 17 root root    4096 Dec 31  1969 pkgs
-r--r--r--  1 root root 3637248 Dec 31  1969 programs.sqlite
-r--r--r--  1 root root    5726 Dec 31  1969 README.md
-r--r--r--  1 root root      18 Dec 31  1969 svn-revision

Note the link nixpkgs -> .

I’m wondering why the default steps in the manual lead to this being the case.

I wonder what happens if in the install steps of section 2.5.4 we replace

$ nix-channel --add https://nixos.org/channels/nixos-19.09 nixpkgs
$ nix-channel --update

with

$ nix-channel --remove nixpkgs
$ nix-channel --add https://nixos.org/channels/nixos-19.09 nixos
$ nix-channel --update

Maybe that’s the issue?

Just as a sanity check, does the following print the same path twice? nix eval '([<nixpkgs> <nixos>])'

1 Like

Looks like it does, and in the case of running as root user, it does not, but the root user’s is symlinked to the same place.

[trusktr@starnix:~]$ nix eval '([<nixpkgs> <nixos>])'
[ /nix/var/nix/profiles/per-user/root/channels/nixos /nix/var/nix/profiles/per-user/root/channels/nixos ]

[trusktr@starnix:~]$ sudo nix eval '([<nixpkgs> <nixos>])'
[sudo] password for trusktr: 
[ /nix/var/nix/profiles/per-user/root/channels/nixos /nix/var/nix/profiles/per-user/root/channels/nixos ]

[trusktr@starnix:~]$ sudo bash

[root@starnix:/home/trusktr]# nix eval '([<nixpkgs> <nixos>])'
[ /nix/var/nix/profiles/per-user/root/channels/nixos /root/.nix-defexpr/channels/nixos ]

@lilyball Should I remove that symlink? Is this a bug in the installation procedure? Or did I mess up?