command-not-found: Add database check to script

We must check for the database every time we use the script so lets add
it to the script itself.

Changed files
+17
nixos
modules
programs
command-not-found
+17
nixos/modules/programs/command-not-found/command-not-found.pl
···
my $dbPath = "@dbPath@";
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbPath", "", "")
or die "cannot open database `$dbPath'";
$dbh->{RaiseError} = 0;
···
my $dbPath = "@dbPath@";
+
if (! -e $dbPath) {
+
print STDERR "$program: command not found\n";
+
print STDERR "\n";
+
print STDERR "command-not-found: Missing package database\n";
+
print STDERR "This likely means the database hasn't been generated yet.\n";
+
print STDERR "This tool requires nix-channels to generate the database.\n";
+
print STDERR "\n";
+
print STDERR "If you are using nix-channels you can run:\n";
+
print STDERR " sudo nix-channels --update\n";
+
print STDERR "\n";
+
print STDERR "If you are using flakes, see nix-index and nix-index-database.\n";
+
print STDERR "\n";
+
print STDERR "If you would like to disable this message you can set:\n";
+
print STDERR " programs.command-not-found.enable = false;\n";
+
exit 127;
+
}
+
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbPath", "", "")
or die "cannot open database `$dbPath'";
$dbh->{RaiseError} = 0;