···
1
+
{ config, lib, pkgs, ... }:
3
+
cfg = config.programs.nix-index;
5
+
options.programs.nix-index = with lib; {
6
+
enable = mkEnableOption (lib.mdDoc "nix-index, a file database for nixpkgs");
9
+
type = types.package;
10
+
default = pkgs.nix-index;
11
+
defaultText = literalExpression "pkgs.nix-index";
12
+
description = lib.mdDoc "Package providing the `nix-index` tool.";
15
+
enableBashIntegration = mkEnableOption (lib.mdDoc "Bash integration") // {
19
+
enableZshIntegration = mkEnableOption (lib.mdDoc "Zsh integration") // {
23
+
enableFishIntegration = mkEnableOption (lib.mdDoc "Fish integration") // {
28
+
config = lib.mkIf cfg.enable {
31
+
assertion = cfg.${name} -> !config.programs.command-not-found.enable;
33
+
The 'programs.command-not-found.enable' option is mutually exclusive
34
+
with the 'programs.nix-index.${name}' option.
37
+
in [ (checkOpt "enableBashIntegration") (checkOpt "enableZshIntegration") ];
39
+
environment.systemPackages = [ cfg.package ];
41
+
programs.bash.interactiveShellInit = lib.mkIf cfg.enableBashIntegration ''
42
+
source ${cfg.package}/etc/profile.d/command-not-found.sh
45
+
programs.zsh.interactiveShellInit = lib.mkIf cfg.enableZshIntegration ''
46
+
source ${cfg.package}/etc/profile.d/command-not-found.sh
49
+
# See https://github.com/bennofs/nix-index/issues/126
50
+
programs.fish.interactiveShellInit = let
51
+
wrapper = pkgs.writeScript "command-not-found" ''
52
+
#!${pkgs.bash}/bin/bash
53
+
source ${cfg.package}/etc/profile.d/command-not-found.sh
54
+
command_not_found_handle "$@"
56
+
in lib.mkIf cfg.enableFishIntegration ''
57
+
function __fish_command_not_found_handler --on-event fish_command_not_found