I’ve created a nixos module implementing a fix I’ve been using for some time for the longtime issue of getting the program database for command-not-found
in a flake-based nixos config. Hope others find it helpful:
This is an interesting way to tackle this problem.
Personally, I’ve set https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz as my nixpkgs flake input which contains programs.sqlite
(this evaluates to for e.g. https://releases.nixos.org/nixos/unstable/nixos-25.11pre818804.08f22084e608/nixexprs.tar.xz thanks to the Lockable HTTP Tarball Protocol). programs.command-not-found.dbPath
could then be set to "${pkgs.path}/programs.sqlite"
.
I don’t use the programs.command-not-found
module and query programs.sqlite
directly, though.
Yeah, setting nixexprs.tar.xz
as a flake input is a reasonable option (I didn’t know about the Lockable HTTP Tarball Protocol, that’s cool!), but it doesn’t technically match your nixpkgs rev automatically (though in practice it’s close as long as you update both inputs together). I wanted something that would always get that correct with no fuss.
Your fish script is neat. I might consider doing my own one of those at some point, but the default command-not-found
is good enough for the moment.
Can you describe the problem that you are restoring; I’m not sure I understand.
I have a flake based NixOS setup ( i think) and it seems to work
> tt
The program 'tt' is currently not installed. It is provided by
several packages. You can install it by typing one of the following:
nix-env -iA nixpkgs.tt.out
nix-env -iA nixpkgs.termtekst.out
nix-env -iA nixpkgs.tasktimer.out
nix-env -iA nixpkgs.rubyPackages_3_4.treetop.out
nix-env -iA nixpkgs.rubyPackages.treetop.out
nix-env -iA nixpkgs.rubyPackages_3_2.treetop.out
nix-env -iA nixpkgs.rubyPackages_3_1.treetop.out
Or run it once with:
nix-shell -p tt.out --run 'tt ...'
nix-shell -p termtekst.out --run 'tt ...'
nix-shell -p tasktimer.out --run 'tt ...'
nix-shell -p rubyPackages_3_4.treetop.out --run 'tt ...'
nix-shell -p rubyPackages.treetop.out --run 'tt ...'
nix-shell -p rubyPackages_3_2.treetop.out --run 'tt ...'
nix-shell -p rubyPackages_3_1.treetop.out --run 'tt ...'
Oh it is this:
> 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 seem to have it “working” due to nix-index
# nix-index provides it's own command-not-found functionality
nix-index.enable = true;
nix-index-database.comma.enable = true;
Yes, it’s that.
There are quite a few other options to get the same behavior floating around, including nix-index, which you apparently forgot you were using.