1 # This module provides suggestions of packages to install if the user
2 # tries to run a missing command in Bash. This is implemented using a
3 # SQLite database that maps program names to Nix package names (e.g.,
4 # "pdflatex" is mapped to "tetex").
14 cfg = config.programs.command-not-found;
15 commandNotFound = pkgs.replaceVarsWith {
16 name = "command-not-found";
18 src = ./command-not-found.pl;
22 perl = pkgs.perl.withPackages (p: [
32 options.programs.command-not-found = {
34 enable = lib.mkOption {
35 type = lib.types.bool;
38 Whether interactive shells should show which Nix package (if
39 any) provides a missing command.
43 dbPath = lib.mkOption {
44 default = "/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite";
46 Absolute path to programs.sqlite.
48 By default this file will be provided by your channel
51 type = lib.types.path;
55 config = lib.mkIf cfg.enable {
56 programs.bash.interactiveShellInit = ''
57 # This function is called whenever a command is not found.
58 command_not_found_handle() {
59 local p='${commandNotFound}/bin/command-not-found'
60 if [ -x "$p" ] && [ -f '${cfg.dbPath}' ]; then
61 # Run the helper program.
63 # Retry the command if we just installed it.
70 echo "$1: command not found" >&2
76 programs.zsh.interactiveShellInit = ''
77 # This function is called whenever a command is not found.
78 command_not_found_handler() {
79 local p='${commandNotFound}/bin/command-not-found'
80 if [ -x "$p" ] && [ -f '${cfg.dbPath}' ]; then
81 # Run the helper program.
84 # Retry the command if we just installed it.
91 # Indicate than there was an error so ZSH falls back to its default handler
92 echo "$1: command not found" >&2
98 environment.systemPackages = [ commandNotFound ];