diff options
author | Jörg Thalheim <joerg@thalheim.io> | 2022-12-25 18:48:59 +0100 |
---|---|---|
committer | Jörg Thalheim <joerg@thalheim.io> | 2022-12-25 22:53:26 +0100 |
commit | f896f689eded225feca7ee50031f83c3893031e9 (patch) | |
tree | b15705d94bdb3ad2701290d36acc5b767b57fc16 /nixos/modules | |
parent | c9101aa310e1258199f9893eb3da88f2d4de1b5d (diff) | |
download | nixpkgs-f896f689eded225feca7ee50031f83c3893031e9.tar nixpkgs-f896f689eded225feca7ee50031f83c3893031e9.tar.gz nixpkgs-f896f689eded225feca7ee50031f83c3893031e9.tar.bz2 nixpkgs-f896f689eded225feca7ee50031f83c3893031e9.tar.lz nixpkgs-f896f689eded225feca7ee50031f83c3893031e9.tar.xz nixpkgs-f896f689eded225feca7ee50031f83c3893031e9.tar.zst nixpkgs-f896f689eded225feca7ee50031f83c3893031e9.zip |
nixos/nix-index: add module
Diffstat (limited to 'nixos/modules')
-rw-r--r-- | nixos/modules/module-list.nix | 1 | ||||
-rw-r--r-- | nixos/modules/programs/nix-index.nix | 62 |
2 files changed, 63 insertions, 0 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index ac40b6cbfd9..c858b4a6fc2 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -201,6 +201,7 @@ ./programs/nbd.nix ./programs/neovim.nix ./programs/nethoscope.nix + ./programs/nix-index.nix ./programs/nix-ld.nix ./programs/nm-applet.nix ./programs/nncp.nix diff --git a/nixos/modules/programs/nix-index.nix b/nixos/modules/programs/nix-index.nix new file mode 100644 index 00000000000..a494b9d8c2c --- /dev/null +++ b/nixos/modules/programs/nix-index.nix @@ -0,0 +1,62 @@ +{ config, lib, pkgs, ... }: +let + cfg = config.programs.nix-index; +in { + options.programs.nix-index = with lib; { + enable = mkEnableOption (lib.mdDoc "nix-index, a file database for nixpkgs"); + + package = mkOption { + type = types.package; + default = pkgs.nix-index; + defaultText = literalExpression "pkgs.nix-index"; + description = lib.mdDoc "Package providing the `nix-index` tool."; + }; + + enableBashIntegration = mkEnableOption (lib.mdDoc "Bash integration") // { + default = true; + }; + + enableZshIntegration = mkEnableOption (lib.mdDoc "Zsh integration") // { + default = true; + }; + + enableFishIntegration = mkEnableOption (lib.mdDoc "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") ]; + + environment.systemPackages = [ cfg.package ]; + + programs.bash.interactiveShellInit = lib.mkIf cfg.enableBashIntegration '' + source ${cfg.package}/etc/profile.d/command-not-found.sh + ''; + + programs.zsh.interactiveShellInit = 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.interactiveShellInit = 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 + ''; + }; +} |