···
11
+
cfg = config.programs.command-not-found;
commandNotFound = pkgs.substituteAll {
name = "command-not-found";
src = ./command-not-found.pl;
18
+
inherit (cfg) dbPath;
perlFlags = concatStrings (map (path: "-I ${path}/lib/perl5/site_perl ")
[ pkgs.perlPackages.DBI pkgs.perlPackages.DBDSQLite pkgs.perlPackages.StringShellQuote ]);
···
26
+
options.programs.command-not-found = {
28
+
enable = mkEnableOption "command-not-found hook for interactive shell";
26
-
programs.bash.interactiveShellInit =
28
-
# This function is called whenever a command is not found.
29
-
command_not_found_handle() {
30
-
local p=/run/current-system/sw/bin/command-not-found
31
-
if [ -x $p -a -f /nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite ]; then
32
-
# Run the helper program.
34
-
# Retry the command if we just installed it.
35
-
if [ $? = 126 ]; then
31
+
default = "/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite" ;
33
+
Absolute path to programs.sqlite.
35
+
By default this file will be provided by your channel
42
+
config = mkIf cfg.enable {
43
+
programs.bash.interactiveShellInit =
45
+
# This function is called whenever a command is not found.
46
+
command_not_found_handle() {
47
+
local p=${commandNotFound}
48
+
if [ -x $p -a -f ${cfg.dbPath} ]; then
49
+
# Run the helper program.
51
+
# Retry the command if we just installed it.
52
+
if [ $? = 126 ]; then
58
+
echo "$1: command not found" >&2
41
-
echo "$1: command not found" >&2
47
-
programs.zsh.interactiveShellInit =
49
-
# This function is called whenever a command is not found.
50
-
command_not_found_handler() {
51
-
local p=/run/current-system/sw/bin/command-not-found
52
-
if [ -x $p -a -f /nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite ]; then
53
-
# Run the helper program.
64
+
programs.zsh.interactiveShellInit =
66
+
# This function is called whenever a command is not found.
67
+
command_not_found_handler() {
68
+
local p=${commandNotFound}
69
+
if [ -x $p -a -f ${cfg.dbPath} ]; then
70
+
# Run the helper program.
56
-
# Retry the command if we just installed it.
57
-
if [ $? = 126 ]; then
73
+
# Retry the command if we just installed it.
74
+
if [ $? = 126 ]; then
78
+
# Indicate than there was an error so ZSH falls back to its default handler
79
+
echo "$1: command not found" >&2
61
-
# Indicate than there was an error so ZSH falls back to its default handler
67
-
environment.systemPackages = [ commandNotFound ];
69
-
# TODO: tab completion for uninstalled commands! :-)
85
+
environment.systemPackages = [ commandNotFound ];