2020-01-14 02:23:20 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.kitty;
|
|
|
|
|
2024-10-07 12:18:19 +02:00
|
|
|
settingsValueType = with types; oneOf [ str bool int float ];
|
2020-01-14 02:23:20 +01:00
|
|
|
|
|
|
|
optionalPackage = opt:
|
|
|
|
optional (opt != null && opt.package != null) opt.package;
|
|
|
|
|
|
|
|
toKittyConfig = generators.toKeyValue {
|
|
|
|
mkKeyValue = key: value:
|
|
|
|
let
|
2022-04-08 06:36:13 +02:00
|
|
|
value' =
|
|
|
|
(if isBool value then lib.hm.booleans.yesNo else toString) value;
|
2020-01-14 02:23:20 +01:00
|
|
|
in "${key} ${value'}";
|
|
|
|
};
|
|
|
|
|
|
|
|
toKittyKeybindings = generators.toKeyValue {
|
|
|
|
mkKeyValue = key: command: "map ${key} ${command}";
|
|
|
|
};
|
|
|
|
|
2021-08-27 04:08:34 +02:00
|
|
|
toKittyEnv =
|
|
|
|
generators.toKeyValue { mkKeyValue = name: value: "env ${name}=${value}"; };
|
|
|
|
|
2023-05-12 11:20:22 +02:00
|
|
|
shellIntegrationInit = {
|
|
|
|
bash = ''
|
|
|
|
if test -n "$KITTY_INSTALLATION_DIR"; then
|
2024-02-05 00:10:32 +01:00
|
|
|
export KITTY_SHELL_INTEGRATION="${cfg.shellIntegration.mode}"
|
2023-05-12 11:20:22 +02:00
|
|
|
source "$KITTY_INSTALLATION_DIR/shell-integration/bash/kitty.bash"
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
fish = ''
|
|
|
|
if set -q KITTY_INSTALLATION_DIR
|
2024-02-05 00:10:32 +01:00
|
|
|
set --global KITTY_SHELL_INTEGRATION "${cfg.shellIntegration.mode}"
|
2023-05-12 11:20:22 +02:00
|
|
|
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
|
2024-02-05 00:10:32 +01:00
|
|
|
export KITTY_SHELL_INTEGRATION="${cfg.shellIntegration.mode}"
|
2023-05-12 11:20:22 +02:00
|
|
|
autoload -Uz -- "$KITTY_INSTALLATION_DIR"/shell-integration/zsh/kitty-integration
|
|
|
|
kitty-integration
|
|
|
|
unfunction kitty-integration
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
shellIntegrationDefaultOpt = {
|
2024-02-05 00:10:32 +01:00
|
|
|
default = !(elem "disabled" (splitString " " cfg.shellIntegration.mode));
|
2023-05-12 11:20:22 +02:00
|
|
|
defaultText = literalExpression ''
|
2024-02-05 00:10:32 +01:00
|
|
|
!(elem "disabled" (splitString " " config.programs.kitty.shellIntegration.mode))
|
2023-05-12 11:20:22 +02:00
|
|
|
'';
|
|
|
|
};
|
2020-01-14 02:23:20 +01:00
|
|
|
in {
|
2024-08-17 19:21:57 +02:00
|
|
|
imports = [
|
|
|
|
(mkChangedOptionModule [ "programs" "kitty" "theme" ] [
|
|
|
|
"programs"
|
|
|
|
"kitty"
|
|
|
|
"themeFile"
|
|
|
|
] (config:
|
|
|
|
let value = getAttrFromPath [ "programs" "kitty" "theme" ] config;
|
|
|
|
in if value != null then
|
|
|
|
(let
|
|
|
|
matching = filter (x: x.name == value) (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 ${value}"
|
|
|
|
strings.removeSuffix ".conf"
|
|
|
|
(strings.removePrefix "themes/" (head matching).file))
|
|
|
|
else
|
|
|
|
null))
|
|
|
|
];
|
|
|
|
|
2020-01-14 02:23:20 +01:00
|
|
|
options.programs.kitty = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "Kitty terminal emulator";
|
2020-01-14 02:23:20 +01:00
|
|
|
|
2022-01-17 00:19:32 +01:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.kitty;
|
|
|
|
defaultText = literalExpression "pkgs.kitty";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-01-17 00:19:32 +01:00
|
|
|
Kitty package to install.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-08-27 04:08:34 +02:00
|
|
|
darwinLaunchOptions = mkOption {
|
|
|
|
type = types.nullOr (types.listOf types.str);
|
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Command-line options to use when launched by Mac OS GUI";
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2021-08-27 04:08:34 +02:00
|
|
|
[
|
|
|
|
"--single-instance"
|
|
|
|
"--directory=/tmp/my-dir"
|
|
|
|
"--listen-on=unix:/tmp/my-socket"
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-01-14 02:23:20 +01:00
|
|
|
settings = mkOption {
|
2024-10-07 12:18:19 +02:00
|
|
|
type = types.attrsOf settingsValueType;
|
2020-01-14 02:23:20 +01:00
|
|
|
default = { };
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2020-01-14 02:23:20 +01:00
|
|
|
{
|
|
|
|
scrollback_lines = 10000;
|
|
|
|
enable_audio_bell = false;
|
|
|
|
update_check_interval = 0;
|
|
|
|
}
|
|
|
|
'';
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2020-01-14 02:23:20 +01:00
|
|
|
Configuration written to
|
2023-07-01 01:30:13 +02:00
|
|
|
{file}`$XDG_CONFIG_HOME/kitty/kitty.conf`. See
|
|
|
|
<https://sw.kovidgoyal.net/kitty/conf.html>
|
2020-01-14 02:23:20 +01:00
|
|
|
for the documentation.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-17 19:21:57 +02:00
|
|
|
themeFile = mkOption {
|
2022-02-08 19:54:24 +01:00
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2024-08-17 19:21:57 +02:00
|
|
|
Apply a Kitty color theme. This option takes the file name of a theme
|
|
|
|
in `kitty-themes`, without the `.conf` suffix. See
|
|
|
|
<https://github.com/kovidgoyal/kitty-themes/tree/master/themes> for a
|
|
|
|
list of themes.
|
2022-02-08 19:54:24 +01:00
|
|
|
'';
|
2024-08-17 19:21:57 +02:00
|
|
|
example = "SpaceGray_Eighties";
|
2022-02-08 19:54:24 +01:00
|
|
|
};
|
|
|
|
|
2020-01-14 02:23:20 +01:00
|
|
|
font = mkOption {
|
|
|
|
type = types.nullOr hm.types.fontType;
|
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "The font to use.";
|
2020-01-14 02:23:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
keybindings = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = { };
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Mapping of keybindings to actions.";
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2020-01-14 02:23:20 +01:00
|
|
|
{
|
|
|
|
"ctrl+c" = "copy_or_interrupt";
|
|
|
|
"ctrl+f>2" = "set_font_size 20";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-08-27 04:08:34 +02:00
|
|
|
environment = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = { };
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Environment variables to set or override.";
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2021-08-27 04:08:34 +02:00
|
|
|
{
|
|
|
|
"LS_COLORS" = "1";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-05-12 11:20:22 +02:00
|
|
|
shellIntegration = {
|
|
|
|
mode = mkOption {
|
|
|
|
type = types.str;
|
2024-02-05 00:10:32 +01:00
|
|
|
default = "no-rc";
|
2023-05-12 23:19:59 +02:00
|
|
|
example = "no-cursor";
|
2024-08-17 19:21:57 +02:00
|
|
|
apply = o:
|
2024-02-05 00:10:32 +01:00
|
|
|
let
|
|
|
|
modes = splitString " " o;
|
|
|
|
filtered = filter (m: m != "no-rc") modes;
|
2024-08-17 19:21:57 +02:00
|
|
|
in concatStringsSep " " (concatLists [ [ "no-rc" ] filtered ]);
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-05-12 11:20:22 +02:00
|
|
|
Set the mode of the shell integration. This accepts the same options
|
2023-07-01 01:30:13 +02:00
|
|
|
as the `shell_integration` option of Kitty. Note that
|
|
|
|
`no-rc` is always implied. See
|
|
|
|
<https://sw.kovidgoyal.net/kitty/shell-integration>
|
2023-05-12 11:20:22 +02:00
|
|
|
for more details.
|
|
|
|
'';
|
|
|
|
};
|
2023-05-12 23:19:59 +02:00
|
|
|
|
2023-07-02 01:45:18 +02:00
|
|
|
enableBashIntegration = mkEnableOption "Kitty Bash integration"
|
2023-05-12 11:20:22 +02:00
|
|
|
// shellIntegrationDefaultOpt;
|
2023-05-12 23:19:59 +02:00
|
|
|
|
2023-07-02 01:45:18 +02:00
|
|
|
enableFishIntegration = mkEnableOption "Kitty fish integration"
|
2023-05-12 11:20:22 +02:00
|
|
|
// shellIntegrationDefaultOpt;
|
2023-05-12 23:19:59 +02:00
|
|
|
|
2023-07-02 01:45:18 +02:00
|
|
|
enableZshIntegration = mkEnableOption "Kitty Z Shell integration"
|
2023-05-12 11:20:22 +02:00
|
|
|
// shellIntegrationDefaultOpt;
|
|
|
|
};
|
|
|
|
|
2020-01-14 02:23:20 +01:00
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Additional configuration to add.";
|
2020-01-14 02:23:20 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2022-01-17 00:19:32 +01:00
|
|
|
home.packages = [ cfg.package ] ++ optionalPackage cfg.font;
|
2020-01-14 02:23:20 +01:00
|
|
|
|
2021-09-05 19:19:37 +02:00
|
|
|
xdg.configFile."kitty/kitty.conf" = {
|
|
|
|
text = ''
|
|
|
|
# Generated by Home Manager.
|
|
|
|
# See https://sw.kovidgoyal.net/kitty/conf.html
|
2024-08-17 19:21:57 +02:00
|
|
|
'' + concatStringsSep "\n" [
|
2022-08-21 01:04:23 +02:00
|
|
|
(optionalString (cfg.font != null) ''
|
2021-09-05 19:19:37 +02:00
|
|
|
font_family ${cfg.font.name}
|
|
|
|
${optionalString (cfg.font.size != null)
|
|
|
|
"font_size ${toString cfg.font.size}"}
|
2022-08-21 01:04:23 +02:00
|
|
|
'')
|
2020-01-14 02:23:20 +01:00
|
|
|
|
2024-08-17 19:21:57 +02:00
|
|
|
(optionalString (cfg.themeFile != null) ''
|
|
|
|
include ${pkgs.kitty-themes}/share/kitty-themes/themes/${cfg.themeFile}.conf
|
2022-08-21 01:04:23 +02:00
|
|
|
'')
|
2023-05-12 11:20:22 +02:00
|
|
|
''
|
|
|
|
# Shell integration is sourced and configured manually
|
2024-02-05 00:10:32 +01:00
|
|
|
shell_integration ${cfg.shellIntegration.mode}
|
2023-05-12 11:20:22 +02:00
|
|
|
''
|
2022-08-21 01:04:23 +02:00
|
|
|
(toKittyConfig cfg.settings)
|
|
|
|
(toKittyKeybindings cfg.keybindings)
|
|
|
|
(toKittyEnv cfg.environment)
|
|
|
|
cfg.extraConfig
|
2024-08-17 19:21:57 +02:00
|
|
|
];
|
2021-10-04 18:20:04 +02:00
|
|
|
} // optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
|
|
|
|
onChange = ''
|
|
|
|
${pkgs.procps}/bin/pkill -USR1 -u $USER kitty || true
|
|
|
|
'';
|
2021-09-05 19:19:37 +02:00
|
|
|
};
|
2021-08-27 04:08:34 +02:00
|
|
|
|
2024-08-17 19:21:57 +02:00
|
|
|
home.activation.checkKittyTheme = mkIf (cfg.themeFile != null) (let
|
|
|
|
themePath =
|
|
|
|
"${pkgs.kitty-themes}/share/kitty-themes/themes/${cfg.themeFile}.conf";
|
|
|
|
in hm.dag.entryBefore [ "writeBoundary" ] ''
|
|
|
|
if [[ ! -f "${themePath}" ]]; then
|
|
|
|
errorEcho "kitty-themes does not contain the theme file ${themePath}!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
'');
|
|
|
|
|
2022-11-27 01:16:33 +01:00
|
|
|
xdg.configFile."kitty/macos-launch-services-cmdline" = mkIf
|
|
|
|
(cfg.darwinLaunchOptions != null && pkgs.stdenv.hostPlatform.isDarwin) {
|
2021-08-27 04:08:34 +02:00
|
|
|
text = concatStringsSep " " cfg.darwinLaunchOptions;
|
|
|
|
};
|
2023-05-12 23:19:59 +02:00
|
|
|
|
2023-05-12 11:20:22 +02:00
|
|
|
programs.bash.initExtra =
|
|
|
|
mkIf cfg.shellIntegration.enableBashIntegration shellIntegrationInit.bash;
|
2023-05-12 23:19:59 +02:00
|
|
|
|
2023-05-12 11:20:22 +02:00
|
|
|
programs.fish.interactiveShellInit =
|
|
|
|
mkIf cfg.shellIntegration.enableFishIntegration shellIntegrationInit.fish;
|
2023-05-12 23:19:59 +02:00
|
|
|
|
2023-05-12 11:20:22 +02:00
|
|
|
programs.zsh.initExtra =
|
|
|
|
mkIf cfg.shellIntegration.enableZshIntegration shellIntegrationInit.zsh;
|
2020-01-14 02:23:20 +01:00
|
|
|
};
|
|
|
|
}
|