fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2let cfg = config . programs . nix-index ; 3in { 4meta . maintainers = with lib . hm . maintainers ; [ ambroisie ]; 5 6options . programs . nix-index = with lib ; { 7enable = mkEnableOption "nix-index, a file database for nixpkgs" ; 8 9package = mkOption { 10type = types . package ; 11default = pkgs . nix-index ; 12defaultText = literalExpression "pkgs.nix-index" ; 13description = "Package providing the {command}`nix-index` tool." ; 14}; 15 16enableBashIntegration = mkEnableOption "Bash integration" // { 17default = true ; 18}; 19 20enableZshIntegration = mkEnableOption "Zsh integration" // { 21default = true ; 22}; 23 24enableFishIntegration = mkEnableOption "Fish integration" // { 25default = true ; 26}; 27}; 28 29config = lib . mkIf cfg . enable { 30assertions = let 31checkOpt = name :{ 32assertion = cfg .${ name } -> ! config . programs . command-not-found . enable ; 33message = '' 34The 'programs.command-not-found.enable' option is mutually exclusive 35with the 'programs.nix-index. ${ name } ' option. 36'' ; 37}; 38in [ ( checkOpt "enableBashIntegration" ) ( checkOpt "enableZshIntegration" ) ]; 39 40home . packages = [ cfg . package ]; 41 42programs . bash . initExtra = lib . mkIf cfg . enableBashIntegration '' 43source ${ cfg . package } /etc/profile.d/command-not-found.sh 44'' ; 45 46programs . zsh . initExtra = lib . mkIf cfg . enableZshIntegration '' 47source ${ cfg . package } /etc/profile.d/command-not-found.sh 48'' ; 49 50# See https://github.com/bennofs/nix-index/issues/126 51programs . fish . shellInit = let 52wrapper = pkgs . writeScript "command-not-found" '' 53#! ${ pkgs . bash } /bin/bash 54source ${ cfg . package } /etc/profile.d/command-not-found.sh 55command_not_found_handle "$@" 56'' ; 57in lib . mkIf cfg . enableFishIntegration '' 58function __fish_command_not_found_handler --on-event fish_command_not_found 59${ wrapper } $argv 60end 61'' ; 62}; 63}