From 9ab0d2305c059937f907a0d3689ac65891b447f3 Mon Sep 17 00:00:00 2001 From: ivann Date: Tue, 14 Jan 2020 02:23:20 +0100 Subject: [PATCH] kitty: add module PR #1000 --- modules/misc/news.nix | 7 +++ modules/modules.nix | 1 + modules/programs/kitty.nix | 91 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 modules/programs/kitty.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 6b01617fc..0d6c2a2cd 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1318,6 +1318,13 @@ in A new module is available: 'programs.neomutt'. ''; } + + { + time = "2020-02-23T10:19:48+00:00"; + message = '' + A new module is available: 'programs.kitty'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 8608a5e69..4ba62ae8e 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -68,6 +68,7 @@ let (loadModule ./programs/jq.nix { }) (loadModule ./programs/kakoune.nix { }) (loadModule ./programs/keychain.nix { }) + (loadModule ./programs/kitty.nix { }) (loadModule ./programs/lesspipe.nix { }) (loadModule ./programs/lsd.nix { }) (loadModule ./programs/man.nix { }) diff --git a/modules/programs/kitty.nix b/modules/programs/kitty.nix new file mode 100644 index 000000000..313a0bfad --- /dev/null +++ b/modules/programs/kitty.nix @@ -0,0 +1,91 @@ +{ 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}"; + }; + +in { + options.programs.kitty = { + enable = mkEnableOption "Kitty terminal emulator"; + + settings = mkOption { + type = types.attrsOf eitherStrBoolInt; + default = { }; + example = literalExample '' + { + scrollback_lines = 10000; + enable_audio_bell = false; + update_check_interval = 0; + } + ''; + description = '' + Configuration written to + ~/.config/kitty/kitty.conf. See + + 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."; + example = literalExample '' + { + "ctrl+c" = "copy_or_interrupt"; + "ctrl+f>2" = "set_font_size 20"; + } + ''; + }; + + extraConfig = mkOption { + default = ""; + type = types.lines; + description = "Additional configuration to add."; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ pkgs.kitty ] ++ optionalPackage cfg.font; + + xdg.configFile."kitty/kitty.conf".text = '' + # Generated by Home Manager. + # See https://sw.kovidgoyal.net/kitty/conf.html + + ${optionalString (cfg.font != null) "font_family ${cfg.font.name}"} + + ${toKittyConfig cfg.settings} + + ${toKittyKeybindings cfg.keybindings} + + ${cfg.extraConfig} + ''; + }; +}