1 { config, lib, pkgs, ... }:
3 cfg = config.programs.nix-index;
5 options.programs.nix-index = with lib; {
6 enable = mkEnableOption "nix-index, a file database for nixpkgs";
8 package = mkPackageOption pkgs "nix-index" { };
10 enableBashIntegration = mkEnableOption "Bash integration" // {
14 enableZshIntegration = mkEnableOption "Zsh integration" // {
18 enableFishIntegration = mkEnableOption "Fish integration" // {
23 config = lib.mkIf cfg.enable {
26 assertion = cfg.${name} -> !config.programs.command-not-found.enable;
28 The 'programs.command-not-found.enable' option is mutually exclusive
29 with the 'programs.nix-index.${name}' option.
32 in [ (checkOpt "enableBashIntegration") (checkOpt "enableZshIntegration") ];
34 environment.systemPackages = [ cfg.package ];
36 programs.bash.interactiveShellInit = lib.mkIf cfg.enableBashIntegration ''
37 source ${cfg.package}/etc/profile.d/command-not-found.sh
40 programs.zsh.interactiveShellInit = lib.mkIf cfg.enableZshIntegration ''
41 source ${cfg.package}/etc/profile.d/command-not-found.sh
44 # See https://github.com/bennofs/nix-index/issues/126
45 programs.fish.interactiveShellInit = let
46 wrapper = pkgs.writeScript "command-not-found" ''
47 #!${pkgs.bash}/bin/bash
48 source ${cfg.package}/etc/profile.d/command-not-found.sh
49 command_not_found_handle "$@"
51 in lib.mkIf cfg.enableFishIntegration ''
52 function __fish_command_not_found_handler --on-event fish_command_not_found