Error: reading symbolic link '/nix/var/nix/profiles/per-user/root/channels/"': No such file or directory

I’m using the “unstable” channel.

I added the following to my configuration.nix:

# Automatic upgrades
system.autoUpgrade = {
  enable = true;
  allowReboot = false; # Do nixos-rebuild switch --upgrade instead
  channel = "https://channels.nixos.org/nixos-unstable";
};

Next, I tried to rebuild, but got an error.

✦ ❯ sudo nixos-rebuild switch --upgrade
error: reading symbolic link '/nix/var/nix/profiles/per-user/root/channels/"': No such file or directory

So I commented out the changes that I had made to configuration.nix, but I’m still getting the error message. I don’t see any problem with the symbolic links in question.

✦ ❯ ls -l /nix/var/nix/profiles/per-user/root/channels/
total 8
lrwxrwxrwx 1 root root 60 Jan  1  1970 manifest.nix -> /nix/store/x8ly1rxc79amaajd92lfim6pjgr5kkbk-env-manifest.nix
lrwxrwxrwx 1 root root 55 Jan  1  1970 nixos -> /nix/store/q3wdxyrjq651dzrg2f3ijgm6a1y87gi2-nixos/nixos

nixos on  main [!?] 
✦ ❯ ls -l /nix/store/x8ly1rxc79amaajd92lfim6pjgr5kkbk-env-manifest.nix
-r--r--r-- 1 root root 234 Jan  1  1970 /nix/store/x8ly1rxc79amaajd92lfim6pjgr5kkbk-env-manifest.nix

nixos on  main [!?] 
✦ ❯ ls -l /nix/store/q3wdxyrjq651dzrg2f3ijgm6a1y87gi2-nixos/nixos
total 12936
-r--r--r-- 1 root root    36284 Jan  1  1970 CONTRIBUTING.md
-r--r--r-- 1 root root     1097 Jan  1  1970 COPYING
-r--r--r-- 1 root root      971 Jan  1  1970 default.nix
dr-xr-xr-x 1 root root      588 Jan  1  1970 doc
-r--r--r-- 1 root root     2661 Jan  1  1970 flake.nix
dr-xr-xr-x 1 root root      796 Jan  1  1970 lib
dr-xr-xr-x 1 root root       96 Jan  1  1970 maintainers
dr-xr-xr-x 1 root root      208 Jan  1  1970 nixos
lrwxrwxrwx 1 root root        1 Jan  1  1970 nixpkgs -> .
dr-xr-xr-x 1 root root      286 Jan  1  1970 pkgs
-r--r--r-- 1 root root 13180928 Jan  1  1970 programs.sqlite
-r--r--r-- 1 root root     5186 Jan  1  1970 README.md
-r--r--r-- 1 root root       20 Jan  1  1970 svn-revision

I ran nix store verify --all; no problems reported.

Just to be sure that I had the channel set properly, I did:

✦ ❯ sudo nix-channel --add https://channels.nixos.org/nixos-unstable nixos

✦ ❯ sudo nix-channel --list | grep nixos

But I still get the error message when I do nixos-rebuild.

2 Likes

I just had the same thing happen to me on two different machines, one of which had no changes to its configuration files. I found a workaround to restore the nix-channels temporarily, but a nixos-rebuild switch will break it again for me.

After running sudo nixos-rebuild switch my sudo nix-channel --list outputs the following

sudo nix-channel --list                                               
" "
nixos "https://nixos.org/channels/nixos-unstable

I remove both entries with
sudo nix-channel --remove nixos and sudo nix-channel --remove \"

And then as you did, add your desired channel again with
sudo nix-channel --add https://channels.nixos.org/nixos-unstable nixos

Which allows me to run sudo nixos-rebuild switch again without errors but it will cause the same broken channel to appear so I need to run this all again each time.

2 Likes

This is a bug, already fixed, see
https://github.com/NixOS/nixpkgs/pull/264608

Edit: Turns out another PR is necessary to completely fix it:

6 Likes