1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-04 18:29:45 +01:00
home-manager/modules/programs/nix-index.nix
Emily 9f9e277b60 treewide: remove now-redundant lib.mdDoc calls
These (and the `*MD` functions apart from `literalMD`) are now no-ops
in nixpkgs and serve no purpose other than to add additional noise and
potentially mislead people into thinking unmarked DocBook documentation
will still be accepted.

Note that if backporting changes including documentation to 23.05,
the `mdDoc` calls will need to be re-added.

To reproduce this commit, run:

    $ NIX_PATH=nixpkgs=flake:nixpkgs/e7e69199f0372364a6106a1e735f68604f4c5a25 \
      nix shell nixpkgs#coreutils \
      -c find . -name '*.nix' \
      -exec nix run -- github:emilazy/nix-doc-munge/98dadf1f77351c2ba5dcb709a2a171d655f15099 \
      --strip {} +
    $ ./format
2023-07-17 18:49:09 +01:00

63 lines
1.9 KiB
Nix

{ 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 = literalExpression "pkgs.nix-index";
description = "Package providing the {command}`nix-index` 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
'';
};
}