at 24.11-pre 1.6 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.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.stdenv.mkDerivation rec { 33 name = "kubeswitch-shell-files"; 34 phases = [ "installPhase" ]; 35 installPhase = '' 36 mkdir -p $out/share 37 for shell in bash zsh; do 38 ${cfg.package}/bin/switcher init $shell | sed 's/switch(/${cfg.commandName}(/' > $out/share/${cfg.commandName}_init.$shell 39 ${cfg.package}/bin/switcher --cmd ${cfg.commandName} completion $shell > $out/share/${cfg.commandName}_completion.$shell 40 done 41 ''; 42 }; 43 in 44 lib.mkIf cfg.enable { 45 environment.systemPackages = [ cfg.package ]; 46 47 programs.bash.interactiveShellInit = '' 48 source ${shell_files}/share/${cfg.commandName}_init.bash 49 source ${shell_files}/share/${cfg.commandName}_completion.bash 50 ''; 51 programs.zsh.interactiveShellInit = '' 52 source ${shell_files}/share/${cfg.commandName}_init.zsh 53 source ${shell_files}/share/${cfg.commandName}_completion.zsh 54 ''; 55 }; 56}