tangled
alpha
login
or
join now
tjh.dev
/
nixpkgs
Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
0
fork
atom
overview
issues
pulls
pipelines
nixos/nix-index: add module
Jörg Thalheim
3 years ago
f896f689
c9101aa3
+63
2 changed files
expand all
collapse all
unified
split
nixos
modules
module-list.nix
programs
nix-index.nix
+1
nixos/modules/module-list.nix
···
201
201
./programs/nbd.nix
202
202
./programs/neovim.nix
203
203
./programs/nethoscope.nix
204
204
+
./programs/nix-index.nix
204
205
./programs/nix-ld.nix
205
206
./programs/nm-applet.nix
206
207
./programs/nncp.nix
+62
nixos/modules/programs/nix-index.nix
···
1
1
+
{ config, lib, pkgs, ... }:
2
2
+
let
3
3
+
cfg = config.programs.nix-index;
4
4
+
in {
5
5
+
options.programs.nix-index = with lib; {
6
6
+
enable = mkEnableOption (lib.mdDoc "nix-index, a file database for nixpkgs");
7
7
+
8
8
+
package = mkOption {
9
9
+
type = types.package;
10
10
+
default = pkgs.nix-index;
11
11
+
defaultText = literalExpression "pkgs.nix-index";
12
12
+
description = lib.mdDoc "Package providing the `nix-index` tool.";
13
13
+
};
14
14
+
15
15
+
enableBashIntegration = mkEnableOption (lib.mdDoc "Bash integration") // {
16
16
+
default = true;
17
17
+
};
18
18
+
19
19
+
enableZshIntegration = mkEnableOption (lib.mdDoc "Zsh integration") // {
20
20
+
default = true;
21
21
+
};
22
22
+
23
23
+
enableFishIntegration = mkEnableOption (lib.mdDoc "Fish integration") // {
24
24
+
default = true;
25
25
+
};
26
26
+
};
27
27
+
28
28
+
config = lib.mkIf cfg.enable {
29
29
+
assertions = let
30
30
+
checkOpt = name: {
31
31
+
assertion = cfg.${name} -> !config.programs.command-not-found.enable;
32
32
+
message = ''
33
33
+
The 'programs.command-not-found.enable' option is mutually exclusive
34
34
+
with the 'programs.nix-index.${name}' option.
35
35
+
'';
36
36
+
};
37
37
+
in [ (checkOpt "enableBashIntegration") (checkOpt "enableZshIntegration") ];
38
38
+
39
39
+
environment.systemPackages = [ cfg.package ];
40
40
+
41
41
+
programs.bash.interactiveShellInit = lib.mkIf cfg.enableBashIntegration ''
42
42
+
source ${cfg.package}/etc/profile.d/command-not-found.sh
43
43
+
'';
44
44
+
45
45
+
programs.zsh.interactiveShellInit = lib.mkIf cfg.enableZshIntegration ''
46
46
+
source ${cfg.package}/etc/profile.d/command-not-found.sh
47
47
+
'';
48
48
+
49
49
+
# See https://github.com/bennofs/nix-index/issues/126
50
50
+
programs.fish.interactiveShellInit = let
51
51
+
wrapper = pkgs.writeScript "command-not-found" ''
52
52
+
#!${pkgs.bash}/bin/bash
53
53
+
source ${cfg.package}/etc/profile.d/command-not-found.sh
54
54
+
command_not_found_handle "$@"
55
55
+
'';
56
56
+
in lib.mkIf cfg.enableFishIntegration ''
57
57
+
function __fish_command_not_found_handler --on-event fish_command_not_found
58
58
+
${wrapper} $argv
59
59
+
end
60
60
+
'';
61
61
+
};
62
62
+
}