I just recently converted my system to use a flake (nixos configuration and standalone home-manager). I assumed that when running in this new flake setup, I no longer need channels. Is that correct?
But, when I try to run comamnd-not-found, I get this:
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 programs.sqlite is published only in channels. I’m not aware of any really nice way for this to work, but on the other hand I find even using a year old DB useful. Right now, maybe it’s easiest to also add a channel (as root) and occasionally sync it.
I personally use nix-index instead and just update it manually from time to time. It has a command-not-found script and gives the benefit of having a handy nix-locate CLI tool for doing more stuff.
I found programs.nix-index.enable in home-manager options. I enabled it, but afterwards, I get this when I try to run it:
❯ nix-index
+ querying available packages
error: querying available packages failed
caused by: nix-env failed with error: nix-env failed with exit code 1:
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixos' does not exist, ignoring
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)
That’s where the additional logic that I posted above comes in, to put the database in place.
EDIT: also, you don’t usually run the nix-index command itself, as it’s used only to create the database. Once you have the database, nix-index is used internally by command-not-found.