Files
nixpkgs/nixos/modules/programs/command-not-found/command-not-found.nix
Jessie Ross be5b0ef699 command-not-found: Simplify the wrappers
- Now we check for database existence in the script.
- Nix ensures the script exists.
- The 126 error code check and retry is leftover from an old version.
2025-06-15 15:56:43 +07:00

72 lines
1.6 KiB
Nix

# This module provides suggestions of packages to install if the user
# tries to run a missing command in Bash. This is implemented using a
# SQLite database that maps program names to Nix package names (e.g.,
# "pdflatex" is mapped to "tetex").
{
config,
lib,
pkgs,
...
}:
let
cfg = config.programs.command-not-found;
commandNotFound = pkgs.replaceVarsWith {
name = "command-not-found";
dir = "bin";
src = ./command-not-found.pl;
isExecutable = true;
replacements = {
inherit (cfg) dbPath;
perl = pkgs.perl.withPackages (p: [
p.DBDSQLite
p.StringShellQuote
]);
};
};
in
{
options.programs.command-not-found = {
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Whether interactive shells should show which Nix package (if
any) provides a missing command.
'';
};
dbPath = lib.mkOption {
default = "/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite";
description = ''
Absolute path to programs.sqlite.
By default this file will be provided by your channel
(nixexprs.tar.xz).
'';
type = lib.types.path;
};
};
config = lib.mkIf cfg.enable {
programs.bash.interactiveShellInit = ''
command_not_found_handle() {
'${commandNotFound}/bin/command-not-found' "$@"
}
'';
programs.zsh.interactiveShellInit = ''
command_not_found_handler() {
'${commandNotFound}/bin/command-not-found' "$@"
}
'';
environment.systemPackages = [ commandNotFound ];
};
}