grafana-alloy: don't build the frontend twice
[NixPkgs.git] / nixos / modules / programs / kubeswitch.nix
blob9348540022f23fcf902b24fb75c6fca64ba1cc9d
2   config,
3   pkgs,
4   lib,
5   ...
6 }:
7 let
8   cfg = config.programs.kubeswitch;
9 in
11   options = {
12     programs.kubeswitch = {
13       enable = lib.mkEnableOption "kubeswitch";
15       commandName = lib.mkOption {
16         type = lib.types.str;
17         default = "kswitch";
18         description = "The name of the command to use";
19       };
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   };
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 ];
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     };