nix-index: add module (#1984)
`nix-index` is a tool to quickly locate the package providing a certain file in `nixpkgs`. It indexes built derivations found in binary caches. This module adds the shell integration for its `command-not-found` script for interactive shells.
This commit is contained in:
parent
7d765d8f46
commit
3b799f6ea4
9 changed files with 149 additions and 0 deletions
63
modules/programs/nix-index.nix
Normal file
63
modules/programs/nix-index.nix
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
let cfg = config.programs.nix-index;
|
||||
in {
|
||||
meta.maintainers = with lib.hm.maintainers; [ ambroisie ];
|
||||
|
||||
options.programs.nix-index = with lib; {
|
||||
enable = mkEnableOption "nix-index, a file database for nixpkgs";
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.nix-index;
|
||||
defaultText = literalExample "pkgs.nix-index";
|
||||
description = "Package providing the <command>nix-index</command> tool.";
|
||||
};
|
||||
|
||||
enableBashIntegration = mkEnableOption "Bash integration" // {
|
||||
default = true;
|
||||
};
|
||||
|
||||
enableZshIntegration = mkEnableOption "Zsh integration" // {
|
||||
default = true;
|
||||
};
|
||||
|
||||
enableFishIntegration = mkEnableOption "Fish integration" // {
|
||||
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
|
||||
programs.fish.shellInit = let
|
||||
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
|
||||
'';
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue