2020-10-12 00:22:58 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.kitty;
|
|
|
|
|
|
|
|
eitherStrBoolInt = with types; either str (either bool int);
|
|
|
|
|
|
|
|
optionalPackage = opt:
|
|
|
|
optional (opt != null && opt.package != null) opt.package;
|
|
|
|
|
|
|
|
toKittyConfig = generators.toKeyValue {
|
|
|
|
mkKeyValue = key: value:
|
|
|
|
let
|
2023-01-10 09:35:00 +00:00
|
|
|
value' =
|
|
|
|
(if isBool value then lib.hm.booleans.yesNo else toString) value;
|
2020-10-12 00:22:58 +00:00
|
|
|
in "${key} ${value'}";
|
|
|
|
};
|
|
|
|
|
|
|
|
toKittyKeybindings = generators.toKeyValue {
|
|
|
|
mkKeyValue = key: command: "map ${key} ${command}";
|
|
|
|
};
|
|
|
|
|
2021-11-04 16:42:44 +00:00
|
|
|
toKittyEnv =
|
|
|
|
generators.toKeyValue { mkKeyValue = name: value: "env ${name}=${value}"; };
|
|
|
|
|
2023-08-08 10:19:01 +00:00
|
|
|
shellIntegrationInit = {
|
|
|
|
bash = ''
|
|
|
|
if test -n "$KITTY_INSTALLATION_DIR"; then
|
|
|
|
source "$KITTY_INSTALLATION_DIR/shell-integration/bash/kitty.bash"
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
fish = ''
|
|
|
|
if set -q KITTY_INSTALLATION_DIR
|
|
|
|
source "$KITTY_INSTALLATION_DIR/shell-integration/fish/vendor_conf.d/kitty-shell-integration.fish"
|
|
|
|
set --prepend fish_complete_path "$KITTY_INSTALLATION_DIR/shell-integration/fish/vendor_completions.d"
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
zsh = ''
|
|
|
|
if test -n "$KITTY_INSTALLATION_DIR"; then
|
|
|
|
autoload -Uz -- "$KITTY_INSTALLATION_DIR"/shell-integration/zsh/kitty-integration
|
|
|
|
kitty-integration
|
|
|
|
unfunction kitty-integration
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
shellIntegrationDefaultOpt = {
|
|
|
|
default = cfg.shellIntegration.mode != "disabled";
|
|
|
|
defaultText = literalExpression ''
|
|
|
|
config.programs.kitty.shellIntegration.mode != "disabled"
|
|
|
|
'';
|
|
|
|
};
|
2020-10-12 00:22:58 +00:00
|
|
|
in {
|
|
|
|
options.programs.kitty = {
|
|
|
|
enable = mkEnableOption "Kitty terminal emulator";
|
|
|
|
|
2023-01-10 09:35:00 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.kitty;
|
|
|
|
defaultText = literalExpression "pkgs.kitty";
|
|
|
|
description = ''
|
|
|
|
Kitty package to install.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-11-04 16:42:44 +00:00
|
|
|
darwinLaunchOptions = mkOption {
|
|
|
|
type = types.nullOr (types.listOf types.str);
|
|
|
|
default = null;
|
|
|
|
description = "Command-line options to use when launched by Mac OS GUI";
|
|
|
|
example = literalExpression ''
|
|
|
|
[
|
|
|
|
"--single-instance"
|
|
|
|
"--directory=/tmp/my-dir"
|
|
|
|
"--listen-on=unix:/tmp/my-socket"
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-10-12 00:22:58 +00:00
|
|
|
settings = mkOption {
|
|
|
|
type = types.attrsOf eitherStrBoolInt;
|
|
|
|
default = { };
|
2021-11-04 16:42:44 +00:00
|
|
|
example = literalExpression ''
|
2020-10-12 00:22:58 +00:00
|
|
|
{
|
|
|
|
scrollback_lines = 10000;
|
|
|
|
enable_audio_bell = false;
|
|
|
|
update_check_interval = 0;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Configuration written to
|
2023-08-08 10:19:01 +00:00
|
|
|
{file}`$XDG_CONFIG_HOME/kitty/kitty.conf`. See
|
|
|
|
<https://sw.kovidgoyal.net/kitty/conf.html>
|
2020-10-12 00:22:58 +00:00
|
|
|
for the documentation.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-01-10 09:35:00 +00:00
|
|
|
theme = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
Apply a Kitty color theme. This option takes the friendly name of
|
2023-08-08 10:19:01 +00:00
|
|
|
any theme given by the command {command}`kitty +kitten themes`.
|
|
|
|
See <https://github.com/kovidgoyal/kitty-themes>
|
2023-01-10 09:35:00 +00:00
|
|
|
for more details.
|
|
|
|
'';
|
|
|
|
example = "Space Gray Eighties";
|
|
|
|
};
|
|
|
|
|
2020-10-12 00:22:58 +00:00
|
|
|
font = mkOption {
|
|
|
|
type = types.nullOr hm.types.fontType;
|
|
|
|
default = null;
|
|
|
|
description = "The font to use.";
|
|
|
|
};
|
|
|
|
|
|
|
|
keybindings = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = { };
|
|
|
|
description = "Mapping of keybindings to actions.";
|
2021-11-04 16:42:44 +00:00
|
|
|
example = literalExpression ''
|
2020-10-12 00:22:58 +00:00
|
|
|
{
|
|
|
|
"ctrl+c" = "copy_or_interrupt";
|
|
|
|
"ctrl+f>2" = "set_font_size 20";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-11-04 16:42:44 +00:00
|
|
|
environment = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = { };
|
|
|
|
description = "Environment variables to set or override.";
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
"LS_COLORS" = "1";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-08-08 10:19:01 +00:00
|
|
|
shellIntegration = {
|
|
|
|
mode = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "enabled";
|
|
|
|
example = "no-cursor";
|
|
|
|
description = ''
|
|
|
|
Set the mode of the shell integration. This accepts the same options
|
|
|
|
as the `shell_integration` option of Kitty. Note that
|
|
|
|
`no-rc` is always implied. See
|
|
|
|
<https://sw.kovidgoyal.net/kitty/shell-integration>
|
|
|
|
for more details.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
enableBashIntegration = mkEnableOption "Kitty Bash integration"
|
|
|
|
// shellIntegrationDefaultOpt;
|
|
|
|
|
|
|
|
enableFishIntegration = mkEnableOption "Kitty fish integration"
|
|
|
|
// shellIntegrationDefaultOpt;
|
|
|
|
|
|
|
|
enableZshIntegration = mkEnableOption "Kitty Z Shell integration"
|
|
|
|
// shellIntegrationDefaultOpt;
|
|
|
|
};
|
|
|
|
|
2020-10-12 00:22:58 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
|
|
|
description = "Additional configuration to add.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2023-01-10 09:35:00 +00:00
|
|
|
home.packages = [ cfg.package ] ++ optionalPackage cfg.font;
|
2020-10-12 00:22:58 +00:00
|
|
|
|
2021-11-04 16:42:44 +00:00
|
|
|
xdg.configFile."kitty/kitty.conf" = {
|
|
|
|
text = ''
|
|
|
|
# Generated by Home Manager.
|
|
|
|
# See https://sw.kovidgoyal.net/kitty/conf.html
|
2023-01-10 09:35:00 +00:00
|
|
|
'' + concatStringsSep "\n" ([
|
2021-11-04 16:42:44 +00:00
|
|
|
|
2023-01-10 09:35:00 +00:00
|
|
|
(optionalString (cfg.font != null) ''
|
2021-11-04 16:42:44 +00:00
|
|
|
font_family ${cfg.font.name}
|
|
|
|
${optionalString (cfg.font.size != null)
|
|
|
|
"font_size ${toString cfg.font.size}"}
|
2023-01-10 09:35:00 +00:00
|
|
|
'')
|
|
|
|
|
|
|
|
(optionalString (cfg.theme != null) ''
|
2023-08-08 10:19:01 +00:00
|
|
|
include ${pkgs.kitty-themes}/share/kitty-themes/${
|
|
|
|
let
|
|
|
|
matching = filter (x: x.name == cfg.theme) (builtins.fromJSON
|
|
|
|
(builtins.readFile
|
|
|
|
"${pkgs.kitty-themes}/share/kitty-themes/themes.json"));
|
|
|
|
in throwIf (length matching == 0)
|
|
|
|
"kitty-themes does not contain a theme named ${cfg.theme}"
|
|
|
|
(head matching).file
|
2023-01-10 09:35:00 +00:00
|
|
|
}
|
|
|
|
'')
|
2023-08-08 10:19:01 +00:00
|
|
|
''
|
|
|
|
# Shell integration is sourced and configured manually
|
|
|
|
shell_integration no-rc ${cfg.shellIntegration.mode}
|
|
|
|
''
|
2023-01-10 09:35:00 +00:00
|
|
|
(toKittyConfig cfg.settings)
|
|
|
|
(toKittyKeybindings cfg.keybindings)
|
|
|
|
(toKittyEnv cfg.environment)
|
|
|
|
cfg.extraConfig
|
|
|
|
]);
|
2021-11-04 16:42:44 +00:00
|
|
|
} // optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
|
|
|
|
onChange = ''
|
|
|
|
${pkgs.procps}/bin/pkill -USR1 -u $USER kitty || true
|
|
|
|
'';
|
|
|
|
};
|
2020-10-12 00:22:58 +00:00
|
|
|
|
2023-01-10 09:35:00 +00:00
|
|
|
xdg.configFile."kitty/macos-launch-services-cmdline" = mkIf
|
|
|
|
(cfg.darwinLaunchOptions != null && pkgs.stdenv.hostPlatform.isDarwin) {
|
2021-11-04 16:42:44 +00:00
|
|
|
text = concatStringsSep " " cfg.darwinLaunchOptions;
|
|
|
|
};
|
2023-08-08 10:19:01 +00:00
|
|
|
|
|
|
|
programs.bash.initExtra =
|
|
|
|
mkIf cfg.shellIntegration.enableBashIntegration shellIntegrationInit.bash;
|
|
|
|
|
|
|
|
programs.fish.interactiveShellInit =
|
|
|
|
mkIf cfg.shellIntegration.enableFishIntegration shellIntegrationInit.fish;
|
|
|
|
|
|
|
|
programs.zsh.initExtra =
|
|
|
|
mkIf cfg.shellIntegration.enableZshIntegration shellIntegrationInit.zsh;
|
2020-10-12 00:22:58 +00:00
|
|
|
};
|
|
|
|
}
|