2013-01-30 14:42:30 +01:00
|
|
|
# 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, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
commandNotFound = pkgs.substituteAll {
|
|
|
|
name = "command-not-found";
|
|
|
|
dir = "bin";
|
|
|
|
src = ./command-not-found.pl;
|
|
|
|
isExecutable = true;
|
|
|
|
inherit (pkgs) perl;
|
|
|
|
perlFlags = concatStrings (map (path: "-I ${path}/lib/perl5/site_perl ")
|
|
|
|
[ pkgs.perlPackages.DBI pkgs.perlPackages.DBDSQLite ]);
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2013-09-18 05:18:34 +02:00
|
|
|
programs.bash.interactiveShellInit =
|
2013-01-30 14:42:30 +01:00
|
|
|
''
|
|
|
|
# This function is called whenever a command is not found.
|
|
|
|
command_not_found_handle() {
|
|
|
|
local p=/run/current-system/sw/bin/command-not-found
|
2013-03-25 14:14:55 +01:00
|
|
|
if [ -x $p -a -f /nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite ]; then
|
2013-01-30 14:42:30 +01:00
|
|
|
# Run the helper program.
|
|
|
|
$p "$1"
|
|
|
|
# Retry the command if we just installed it.
|
|
|
|
if [ $? = 126 ]; then
|
|
|
|
"$@"
|
2013-05-15 12:47:17 +02:00
|
|
|
else
|
|
|
|
return 127
|
2013-01-30 14:42:30 +01:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "$1: command not found" >&2
|
2013-05-15 12:47:17 +02:00
|
|
|
return 127
|
2013-01-30 14:42:30 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
environment.systemPackages = [ commandNotFound ];
|
|
|
|
|
|
|
|
# TODO: tab completion for uninstalled commands! :-)
|
|
|
|
|
|
|
|
}
|