Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{
2 config,
3 pkgs,
4 lib,
5 ...
6}:
7let
8 cfg = config.programs.kubeswitch;
9in
10{
11 options = {
12 programs.kubeswitch = {
13 enable = lib.mkEnableOption "kubeswitch";
14
15 commandName = lib.mkOption {
16 type = lib.types.str;
17 default = "kswitch";
18 description = "The name of the command to use";
19 };
20
21 package = lib.mkOption {
22 type = lib.types.package;
23 default = pkgs.kubeswitch;
24 defaultText = lib.literalExpression "pkgs.kubeswitch";
25 description = "The package to install for kubeswitch";
26 };
27 };
28 };
29
30 config =
31 let
32 shell_files = pkgs.runCommand "kubeswitch-shell-files" { } ''
33 mkdir -p $out/share
34 for shell in bash zsh; do
35 ${cfg.package}/bin/switcher init $shell | sed 's/switch(/${cfg.commandName}(/' > $out/share/${cfg.commandName}_init.$shell
36 ${cfg.package}/bin/switcher --cmd ${cfg.commandName} completion $shell > $out/share/${cfg.commandName}_completion.$shell
37 done
38 '';
39 in
40 lib.mkIf cfg.enable {
41 environment.systemPackages = [ cfg.package ];
42
43 programs.bash.interactiveShellInit = ''
44 source ${shell_files}/share/${cfg.commandName}_init.bash
45 source ${shell_files}/share/${cfg.commandName}_completion.bash
46 '';
47 programs.zsh.interactiveShellInit = ''
48 source ${shell_files}/share/${cfg.commandName}_init.zsh
49 source ${shell_files}/share/${cfg.commandName}_completion.zsh
50 '';
51 };
52}