fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

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