command-not-found: disable by default, simplify, document (#416425)
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
- `base16-builder` node package has been removed due to lack of upstream maintenance.
|
||||
- `gentium` package now provides `Gentium-*.ttf` files, and not `GentiumPlus-*.ttf` files like before. The font identifiers `Gentium Plus*` are available in the `gentium-plus` package, and if you want to use the more recently updated package `gentium` [by sil](https://software.sil.org/gentium/), you should update your configuration files to use the `Gentium` font identifier.
|
||||
- `space-orbit` package has been removed due to lack of upstream maintenance. Debian upstream stopped tracking it in 2011.
|
||||
- `command-not-found` package is now disabled by default; it works only for nix-channels based systems, and requires setup for it to work.
|
||||
|
||||
- `gnome-keyring` no longer ships with an SSH agent anymore because it has been deprecated upstream. You should use `gcr_4` instead, which provides the same features. More information on why this was done can be found on [the relevant GCR upstream PR](https://gitlab.gnome.org/GNOME/gcr/-/merge_requests/67).
|
||||
|
||||
|
||||
@@ -33,10 +33,16 @@ in
|
||||
|
||||
enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether interactive shells should show which Nix package (if
|
||||
any) provides a missing command.
|
||||
|
||||
Requires nix-channels to be set and downloaded (sudo nix-channels --update.)
|
||||
|
||||
See also nix-index and nix-index-database as an alternative for flakes-based systems.
|
||||
|
||||
Additionally, having the env var NIX_AUTO_RUN set will automatically run the matching package, and with NIX_AUTO_RUN_INTERACTIVE it will confirm the package before running.
|
||||
'';
|
||||
};
|
||||
|
||||
@@ -54,47 +60,24 @@ in
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
programs.bash.interactiveShellInit = ''
|
||||
# This function is called whenever a command is not found.
|
||||
command_not_found_handle() {
|
||||
local p='${commandNotFound}/bin/command-not-found'
|
||||
if [ -x "$p" ] && [ -f '${cfg.dbPath}' ]; then
|
||||
# Run the helper program.
|
||||
"$p" "$@"
|
||||
# Retry the command if we just installed it.
|
||||
if [ $? = 126 ]; then
|
||||
"$@"
|
||||
else
|
||||
return 127
|
||||
fi
|
||||
else
|
||||
echo "$1: command not found" >&2
|
||||
return 127
|
||||
fi
|
||||
'${commandNotFound}/bin/command-not-found' "$@"
|
||||
}
|
||||
'';
|
||||
|
||||
programs.zsh.interactiveShellInit = ''
|
||||
# This function is called whenever a command is not found.
|
||||
command_not_found_handler() {
|
||||
local p='${commandNotFound}/bin/command-not-found'
|
||||
if [ -x "$p" ] && [ -f '${cfg.dbPath}' ]; then
|
||||
# Run the helper program.
|
||||
"$p" "$@"
|
||||
|
||||
# Retry the command if we just installed it.
|
||||
if [ $? = 126 ]; then
|
||||
"$@"
|
||||
else
|
||||
return 127
|
||||
fi
|
||||
else
|
||||
# Indicate than there was an error so ZSH falls back to its default handler
|
||||
echo "$1: command not found" >&2
|
||||
return 127
|
||||
fi
|
||||
'${commandNotFound}/bin/command-not-found' "$@"
|
||||
}
|
||||
'';
|
||||
|
||||
# NOTE: Fish by itself checks for nixos command-not-found, let's instead makes it explicit.
|
||||
programs.fish.interactiveShellInit = ''
|
||||
function fish_command_not_found
|
||||
"${commandNotFound}/bin/command-not-found" $argv
|
||||
end
|
||||
'';
|
||||
|
||||
environment.systemPackages = [ commandNotFound ];
|
||||
};
|
||||
|
||||
|
||||
@@ -10,6 +10,24 @@ my $program = $ARGV[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 "command-not-found is a tool for searching for missing packages.\n";
|
||||
print STDERR "No database was found, this likely means the database hasn't been generated yet.\n";
|
||||
print STDERR "This tool requires nix-channels to generate the database for the `nixos` channel.\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;
|
||||
|
||||
Reference in New Issue
Block a user