at master 1.3 kB view raw
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.mkPackageOption pkgs "kubeswitch" { }; 22 }; 23 }; 24 25 config = 26 let 27 shell_files = pkgs.runCommand "kubeswitch-shell-files" { } '' 28 mkdir -p $out/share 29 for shell in bash zsh; do 30 ${cfg.package}/bin/switcher init $shell | sed 's/switch(/${cfg.commandName}(/' > $out/share/${cfg.commandName}_init.$shell 31 ${cfg.package}/bin/switcher --cmd ${cfg.commandName} completion $shell > $out/share/${cfg.commandName}_completion.$shell 32 done 33 ''; 34 in 35 lib.mkIf cfg.enable { 36 environment.systemPackages = [ cfg.package ]; 37 38 programs.bash.interactiveShellInit = '' 39 source ${shell_files}/share/${cfg.commandName}_init.bash 40 source ${shell_files}/share/${cfg.commandName}_completion.bash 41 ''; 42 programs.zsh.interactiveShellInit = '' 43 source ${shell_files}/share/${cfg.commandName}_init.zsh 44 source ${shell_files}/share/${cfg.commandName}_completion.zsh 45 ''; 46 }; 47}