fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
1.4 KiB54 linesraw
1# Adapted from Nixpkgs.
2
3{ config, lib, pkgs, ... }:
4
5with lib;
6
7let
8  cfg = config.programs.command-not-found;
9  commandNotFound = pkgs.substituteAll {
10    name = "command-not-found";
11    dir = "bin";
12    src = ./command-not-found.pl;
13    isExecutable = true;
14    inherit (cfg) dbPath;
15    perl = pkgs.perl.withPackages (p: [ p.DBDSQLite p.StringShellQuote ]);
16  };
17
18  shInit = commandNotFoundHandlerName: ''
19    # This function is called whenever a command is not found.
20    ${commandNotFoundHandlerName}() {
21      local p=${commandNotFound}/bin/command-not-found
22      if [ -x $p -a -f ${cfg.dbPath} ]; then
23        # Run the helper program.
24        $p "$@"
25      else
26        echo "$1: command not found" >&2
27        return 127
28      fi
29    }
30  '';
31
32in {
33  options.programs.command-not-found = {
34    enable = mkEnableOption "command-not-found hook for interactive shell";
35
36    dbPath = mkOption {
37      default =
38        "/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite";
39      description = ''
40        Absolute path to {file}`programs.sqlite`. By
41        default this file will be provided by your channel
42        (nixexprs.tar.xz).
43      '';
44      type = types.path;
45    };
46  };
47
48  config = mkIf cfg.enable {
49    programs.bash.initExtra = shInit "command_not_found_handle";
50    programs.zsh.initExtra = shInit "command_not_found_handler";
51
52    home.packages = [ commandNotFound ];
53  };
54}