fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . programs . kitty ; 8 9eitherStrBoolInt = with types ; either str ( either bool int ); 10 11optionalPackage = opt : 12optional ( opt != null && opt . package != null ) opt . package ; 13 14toKittyConfig = generators . toKeyValue { 15mkKeyValue = key :value : 16let 17value' = 18( if isBool value then lib . hm . booleans . yesNo else toString ) value ; 19in " ${ key } ${ value' } " ; 20}; 21 22toKittyKeybindings = generators . toKeyValue { 23mkKeyValue = key :command :"map ${ key } ${ command } " ; 24}; 25 26toKittyEnv = 27generators . toKeyValue { mkKeyValue = name :value :"env ${ name } = ${ value } " ; }; 28 29shellIntegrationInit = { 30bash = '' 31if test -n "$KITTY_INSTALLATION_DIR"; then 32source "$KITTY_INSTALLATION_DIR/shell-integration/bash/kitty.bash" 33fi 34'' ; 35fish = '' 36if set -q KITTY_INSTALLATION_DIR 37source "$KITTY_INSTALLATION_DIR/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish" 38set --prepend fish_complete_path "$KITTY_INSTALLATION_DIR/shell-integration/fish/vendor_completions.d" 39end 40'' ; 41zsh = '' 42if test -n "$KITTY_INSTALLATION_DIR"; then 43autoload -Uz -- "$KITTY_INSTALLATION_DIR"/shell-integration/zsh/kitty-integration 44kitty-integration 45unfunction kitty-integration 46fi 47'' ; 48}; 49 50shellIntegrationDefaultOpt = { 51default = cfg . shellIntegration . mode != "disabled" ; 52defaultText = literalExpression '' 53config.programs.kitty.shellIntegration.mode != "disabled" 54'' ; 55}; 56in { 57options . programs . kitty = { 58enable = mkEnableOption "Kitty terminal emulator" ; 59 60package = mkOption { 61type = types . package ; 62default = pkgs . kitty ; 63defaultText = literalExpression "pkgs.kitty" ; 64description = '' 65Kitty package to install. 66'' ; 67}; 68 69darwinLaunchOptions = mkOption { 70type = types . nullOr ( types . listOf types . str ); 71default = null ; 72description = "Command-line options to use when launched by Mac OS GUI" ; 73example = literalExpression '' 74[ 75"--single-instance" 76"--directory=/tmp/my-dir" 77"--listen-on=unix:/tmp/my-socket" 78] 79'' ; 80}; 81 82settings = mkOption { 83type = types . attrsOf eitherStrBoolInt ; 84default = { }; 85example = literalExpression '' 86{ 87scrollback_lines = 10000; 88enable_audio_bell = false; 89update_check_interval = 0; 90} 91'' ; 92description = '' 93Configuration written to 94{file}`$XDG_CONFIG_HOME/kitty/kitty.conf`. See 95<https://sw.kovidgoyal.net/kitty/conf.html> 96for the documentation. 97'' ; 98}; 99 100theme = mkOption { 101type = types . nullOr types . str ; 102default = null ; 103description = '' 104Apply a Kitty color theme. This option takes the friendly name of 105any theme given by the command {command}`kitty +kitten themes`. 106See <https://github.com/kovidgoyal/kitty-themes> 107for more details. 108'' ; 109example = "Space Gray Eighties" ; 110}; 111 112font = mkOption { 113type = types . nullOr hm . types . fontType ; 114default = null ; 115description = "The font to use." ; 116}; 117 118keybindings = mkOption { 119type = types . attrsOf types . str ; 120default = { }; 121description = "Mapping of keybindings to actions." ; 122example = literalExpression '' 123{ 124"ctrl+c" = "copy_or_interrupt"; 125"ctrl+f>2" = "set_font_size 20"; 126} 127'' ; 128}; 129 130environment = mkOption { 131type = types . attrsOf types . str ; 132default = { }; 133description = "Environment variables to set or override." ; 134example = literalExpression '' 135{ 136"LS_COLORS" = "1"; 137} 138'' ; 139}; 140 141shellIntegration = { 142mode = mkOption { 143type = types . str ; 144default = "enabled" ; 145example = "no-cursor" ; 146description = '' 147Set the mode of the shell integration. This accepts the same options 148as the `shell_integration` option of Kitty. Note that 149`no-rc` is always implied. See 150<https://sw.kovidgoyal.net/kitty/shell-integration> 151for more details. 152'' ; 153}; 154 155enableBashIntegration = mkEnableOption "Kitty Bash integration" 156// shellIntegrationDefaultOpt ; 157 158enableFishIntegration = mkEnableOption "Kitty fish integration" 159// shellIntegrationDefaultOpt ; 160 161enableZshIntegration = mkEnableOption "Kitty Z Shell integration" 162// shellIntegrationDefaultOpt ; 163}; 164 165extraConfig = mkOption { 166default = "" ; 167type = types . lines ; 168description = "Additional configuration to add." ; 169}; 170}; 171 172config = mkIf cfg . enable { 173home . packages = [ cfg . package ] ++ optionalPackage cfg . font ; 174 175xdg . configFile . "kitty/kitty.conf" = { 176text = '' 177# Generated by Home Manager. 178# See https://sw.kovidgoyal.net/kitty/conf.html 179'' + concatStringsSep "\n" ([ 180 181( optionalString ( cfg . font != null ) '' 182font_family ${ cfg . font . name } 183${ optionalString ( cfg . font . size != null ) 184"font_size ${ toString cfg . font . size } " } 185'' ) 186 187( optionalString ( cfg . theme != null ) '' 188include ${ pkgs . kitty-themes } /share/kitty-themes/ ${ 189let 190matching = filter ( x : x . name == cfg . theme ) ( builtins . fromJSON 191( builtins . readFile 192" ${ pkgs . kitty-themes } /share/kitty-themes/themes.json" )); 193in throwIf ( length matching == 0 ) 194"kitty-themes does not contain a theme named ${ cfg . theme } " 195( head matching ). file 196} 197'' ) 198'' 199# Shell integration is sourced and configured manually 200shell_integration no-rc ${ cfg . shellIntegration . mode } 201'' 202( toKittyConfig cfg . settings ) 203( toKittyKeybindings cfg . keybindings ) 204( toKittyEnv cfg . environment ) 205cfg . extraConfig 206]); 207} // optionalAttrs pkgs . stdenv . hostPlatform . isLinux { 208onChange = '' 209${ pkgs . procps } /bin/pkill -USR1 -u $USER kitty || true 210'' ; 211}; 212 213xdg . configFile . "kitty/macos-launch-services-cmdline" = mkIf 214( cfg . darwinLaunchOptions != null && pkgs . stdenv . hostPlatform . isDarwin ) { 215text = concatStringsSep " " cfg . darwinLaunchOptions ; 216}; 217 218programs . bash . initExtra = 219mkIf cfg . shellIntegration . enableBashIntegration shellIntegrationInit . bash ; 220 221programs . fish . interactiveShellInit = 222mkIf cfg . shellIntegration . enableFishIntegration shellIntegrationInit . fish ; 223 224programs . zsh . initExtra = 225mkIf cfg . shellIntegration . enableZshIntegration shellIntegrationInit . zsh ; 226}; 227}