2020-01-14 02:23:20 +01: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
|
|
|
|
value' = if isBool value then
|
|
|
|
(if value then "yes" else "no")
|
|
|
|
else
|
|
|
|
toString value;
|
|
|
|
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}"; };
|
|
|
|
|
2020-01-14 02:23:20 +01:00
|
|
|
in {
|
|
|
|
options.programs.kitty = {
|
|
|
|
enable = mkEnableOption "Kitty terminal emulator";
|
|
|
|
|
2022-01-17 00:19:32 +01:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.kitty;
|
|
|
|
defaultText = literalExpression "pkgs.kitty";
|
|
|
|
description = ''
|
|
|
|
Kitty package to install.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-08-27 04:08:34 +02:00
|
|
|
darwinLaunchOptions = mkOption {
|
|
|
|
type = types.nullOr (types.listOf types.str);
|
|
|
|
default = null;
|
|
|
|
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 {
|
|
|
|
type = types.attrsOf eitherStrBoolInt;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Configuration written to
|
2021-12-09 04:02:00 +01:00
|
|
|
<filename>$XDG_CONFIG_HOME/kitty/kitty.conf</filename>. See
|
2020-01-14 02:23:20 +01:00
|
|
|
<link xlink:href="https://sw.kovidgoyal.net/kitty/conf.html" />
|
|
|
|
for the documentation.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
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-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 = { };
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-01-14 02:23:20 +01:00
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
|
|
|
description = "Additional configuration to add.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-08-27 04:08:34 +02:00
|
|
|
assertions = [{
|
|
|
|
assertion = (cfg.darwinLaunchOptions != null)
|
|
|
|
-> pkgs.stdenv.hostPlatform.isDarwin;
|
|
|
|
message = ''
|
|
|
|
The 'programs.kitty.darwinLaunchOptions' option is only available on darwin.
|
|
|
|
'';
|
|
|
|
}];
|
|
|
|
|
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
|
2020-01-14 02:23:20 +01:00
|
|
|
|
2021-09-05 19:19:37 +02:00
|
|
|
${optionalString (cfg.font != null) ''
|
|
|
|
font_family ${cfg.font.name}
|
|
|
|
${optionalString (cfg.font.size != null)
|
|
|
|
"font_size ${toString cfg.font.size}"}
|
|
|
|
''}
|
2020-01-14 02:23:20 +01:00
|
|
|
|
2021-09-05 19:19:37 +02:00
|
|
|
${toKittyConfig cfg.settings}
|
2020-01-14 02:23:20 +01:00
|
|
|
|
2021-09-05 19:19:37 +02:00
|
|
|
${toKittyKeybindings cfg.keybindings}
|
2020-01-14 02:23:20 +01:00
|
|
|
|
2021-09-05 19:19:37 +02:00
|
|
|
${toKittyEnv cfg.environment}
|
2021-08-27 04:08:34 +02:00
|
|
|
|
2021-09-05 19:19:37 +02:00
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
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
|
|
|
|
|
|
|
xdg.configFile."kitty/macos-launch-services-cmdline" =
|
|
|
|
mkIf (cfg.darwinLaunchOptions != null) {
|
|
|
|
text = concatStringsSep " " cfg.darwinLaunchOptions;
|
|
|
|
};
|
2020-01-14 02:23:20 +01:00
|
|
|
};
|
|
|
|
}
|