-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhm-module.nix
74 lines (62 loc) · 2.02 KB
/
hm-module.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
self:
{
config,
lib,
pkgs,
...
}:
with lib;
let
cfg = config.programs.krewfile;
finalPackage = self.packages.${pkgs.system}.krewfile;
krewfileContent = pkgs.writeText "krewfile" (
(concatStringsSep "\n" (map (key: "index ${key} ${getAttr key cfg.indexes}") (attrNames cfg.indexes))) + "\n\n" + (concatStringsSep "\n" cfg.plugins)
);
args = if cfg.upgrade then "-upgrade" else "";
in
{
options.programs.krewfile = {
enable = mkEnableOption "krewfile";
krewPackage = mkOption {
type = types.package;
default = pkgs.krew;
defaultText = literalExpression "pkgs.krew";
description = "Krew package to install.";
};
krewRoot = mkOption {
type = types.path;
default = "${config.home.homeDirectory}/.krew";
description = "Path where all krew-related files will be installed and stored.";
};
plugins = mkOption {
type = with types; listOf str;
default = [ ];
defaultText = literalExpression "[ "edit-status" ]";
description = "List of plugins to be installed.";
};
indexes = mkOption {
type = with types; attrsOf str;
default = { };
defaultText = ''{ netshoot = "https://github.com/nilic/kubectl-netshoot.git" }'';
description = "List of extra indexes to be added, where key is index name, and value is index URL";
};
upgrade = mkOption {
type = types.bool;
default = false;
defaultText = literalExpression "false";
description = "Enable auto update of plugins.";
};
};
config = mkIf cfg.enable {
home.packages = [ finalPackage cfg.krewPackage ];
home.extraActivationPath = [ pkgs.git ];
home.sessionVariables.KREW_ROOT = "${cfg.krewRoot}";
home.sessionPath = [ "${cfg.krewRoot}/bin" ];
home.activation.krew = hm.dag.entryAfter [ "installPackages" ] ''
KREW_ROOT="${cfg.krewRoot}";
run ${finalPackage}/bin/${finalPackage.pname} \
-command ${cfg.krewPackage}/bin/${cfg.krewPackage.pname} \
-file ${krewfileContent} ${args}
'';
};
}