2021-05-10 00:13:10 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let cfg = config.programs.nix-index;
|
|
|
|
in {
|
|
|
|
meta.maintainers = with lib.hm.maintainers; [ ambroisie ];
|
|
|
|
|
|
|
|
options.programs.nix-index = with lib; {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "nix-index, a file database for nixpkgs";
|
2021-05-10 00:13:10 +02:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.nix-index;
|
2021-10-09 11:14:08 +02:00
|
|
|
defaultText = literalExpression "pkgs.nix-index";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Package providing the {command}`nix-index` tool.";
|
2021-05-10 00:13:10 +02:00
|
|
|
};
|
|
|
|
|
2023-07-02 01:45:18 +02:00
|
|
|
enableBashIntegration = mkEnableOption "Bash integration" // {
|
2021-05-10 00:13:10 +02:00
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
|
2023-07-02 01:45:18 +02:00
|
|
|
enableZshIntegration = mkEnableOption "Zsh integration" // {
|
2021-05-10 00:13:10 +02:00
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
|
2023-07-02 01:45:18 +02:00
|
|
|
enableFishIntegration = mkEnableOption "Fish integration" // {
|
2021-05-10 00:13:10 +02:00
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
assertions = let
|
|
|
|
checkOpt = name: {
|
|
|
|
assertion = cfg.${name} -> !config.programs.command-not-found.enable;
|
|
|
|
message = ''
|
|
|
|
The 'programs.command-not-found.enable' option is mutually exclusive
|
|
|
|
with the 'programs.nix-index.${name}' option.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in [ (checkOpt "enableBashIntegration") (checkOpt "enableZshIntegration") ];
|
|
|
|
|
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
|
|
|
|
programs.bash.initExtra = lib.mkIf cfg.enableBashIntegration ''
|
|
|
|
source ${cfg.package}/etc/profile.d/command-not-found.sh
|
|
|
|
'';
|
|
|
|
|
|
|
|
programs.zsh.initExtra = lib.mkIf cfg.enableZshIntegration ''
|
|
|
|
source ${cfg.package}/etc/profile.d/command-not-found.sh
|
|
|
|
'';
|
|
|
|
|
|
|
|
# See https://github.com/bennofs/nix-index/issues/126
|
2023-12-21 12:19:17 +01:00
|
|
|
programs.fish.interactiveShellInit = let
|
2021-05-10 00:13:10 +02:00
|
|
|
wrapper = pkgs.writeScript "command-not-found" ''
|
|
|
|
#!${pkgs.bash}/bin/bash
|
|
|
|
source ${cfg.package}/etc/profile.d/command-not-found.sh
|
|
|
|
command_not_found_handle "$@"
|
|
|
|
'';
|
|
|
|
in lib.mkIf cfg.enableFishIntegration ''
|
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
|
|
|
${wrapper} $argv
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|