I am on NixOS and command-not-found feature is no longer working.
I don’t have any configuration for it in configuration.nix, it should enable by default.
What should I do to fix it?
$ command-not-found
DBI connect('dbname=/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite','',...) failed: unable to open database file at /run/current-system/sw/bin/command-not-found line 13.
cannot open database `/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite' at /run/current-system/sw/bin/command-not-found line 13.
I’ve had that issue as well. What you need to make sure is that root’s channels include a channel named nixos. You can point it to a nixos-unstable.
If all of your channels are deleted (use nix-channel --delete and nix-channel --list to view them), you can add the unstable channel and name it unstable with:
Too bad this doesn’t work, I already have nixos-unstable as nixos (for root).
Any idea?
[root@earth:~]# nix-channel --list
nixos https://nixos.org/channels/nixpkgs-unstable
[root@earth:~]# command-not-found
DBI connect('dbname=/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite','',...) failed: unable to open database file at /run/current-system/sw/bin/command-not-found line 13.
cannot open database `/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite' at /run/current-system/sw/bin/command-not-found line 13.
[wizzup@ ~]$ nix-channel --list
[wizzup@ ~]$ command-not-found
DBI connect('dbname=/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite','',...) failed: unable to open database file at /run/current-system/sw/bin/command-not-found line 13.
cannot open database `/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite' at /run/current-system/sw/bin/command-not-found line 13.
This works! Do I need to do this command sequences every time after nixos-rebuild switch?
[root@earth:~]# nix-channel --add https://nixos.org/channels/nixos-unstable nixos
[root@earth:~]# nix-channel --list
nixos https://nixos.org/channels/nixos-unstable
[root@earth:~]# nix-channel --update
unpacking channels...
[root@earth:~]# command-not-found hello
The program ‘hello’ is currently not installed. It is provided by
several packages. You can install it by typing one of the following:
nix-env -iA nixos.hello
nix-env -iA nixos.mbedtls
nix-env -iA nixos.perkeep
I’m seeing this in 21.11, and none of the above suggestions appear to work for me.
My root user appears to have the correct channel:
$ id
uid=0(root) gid=0(root) groups=0(root)
$ nix-channel --list
nixos https://nixos.org/channels/nixos-21.11
But command-not-found still can’t find the database:
$ command-not-found
DBI connect('dbname=/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite','',...) failed: unable to open database file at /run/current-system/sw/bin/command-not-found line 13.
cannot open database `/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite' at /run/current-system/sw/bin/command-not-found line 13.
This error message seems reasonable, since the programs.sqlite database really doesn’t exist:
$ ls -lah /nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite
ls: cannot access '/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite': No such file or directory
$ ls -lah /nix/var/nix/profiles/per-user/root/channels/nixos/
total 88K
dr-xr-xr-x 8 root root 4.0K Jan 1 1970 .
dr-xr-xr-x 3 root root 4.0K Jan 1 1970 ..
-r--r--r-- 1 root root 4.9K Jan 1 1970 CONTRIBUTING.md
-r--r--r-- 1 root root 1.1K Jan 1 1970 COPYING
-r--r--r-- 1 root root 971 Jan 1 1970 default.nix
dr-xr-xr-x 11 root root 4.0K Jan 1 1970 doc
-r--r--r-- 1 root root 2.3K Jan 1 1970 .editorconfig
-r--r--r-- 1 root root 3.3K Jan 1 1970 flake.nix
-r--r--r-- 1 root root 598 Jan 1 1970 .gitattributes
dr-xr-xr-x 4 root root 4.0K Jan 1 1970 .github
-r--r--r-- 1 root root 344 Jan 1 1970 .gitignore
-r--r--r-- 1 root root 40 Jan 1 1970 .git-revision
dr-xr-xr-x 4 root root 4.0K Jan 1 1970 lib
dr-xr-xr-x 3 root root 4.0K Jan 1 1970 maintainers
dr-xr-xr-x 7 root root 4.0K Jan 1 1970 nixos
lrwxrwxrwx 1 root root 1 Jan 1 1970 nixpkgs -> .
dr-xr-xr-x 18 root root 4.0K Jan 1 1970 pkgs
-r--r--r-- 1 root root 5.8K Jan 1 1970 README.md
-r--r--r-- 1 root root 20 Jan 1 1970 svn-revision
-r--r--r-- 1 root root 5 Jan 1 1970 .version
-r--r--r-- 1 root root 19 Jan 1 1970 .version-suffix
So now the question is, is running nix-channel --update at least once required? Or are there just certain channel commits that don’t have a programs.sqlite generated?
In case you are using Nix Flakes, then you can use nix-index for the command-not-found functionality. If you use home-manager, add this to your home.nix: