aboutsummaryrefslogtreecommitdiff
path: root/home-manager/modules/programs/kitty.nix
blob: 313a0bfadd77f09169201226fe39ad56656f381d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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
        <filename>~/.config/kitty/kitty.conf</filename>. See
        <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.";
      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}
    '';
  };
}