forked from malob/nixpkgs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextras.nix
134 lines (106 loc) · 4.19 KB
/
extras.nix
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.kitty.extras;
# Create a Kitty config string from a Nix set
setToKittyConfig = with generators; toKeyValue { mkKeyValue = mkKeyValueDefault {} " "; };
# Write a Nix set representing a kitty config into the Nix store
writeKittyConfig = fileName: config: pkgs.writeTextDir "${fileName}" (setToKittyConfig config);
# Path in Nix store containing light and dark kitty color configs
kitty-colors = pkgs.symlinkJoin {
name = "kitty-colors";
paths = [
(writeKittyConfig "dark-colors.conf" cfg.colors.dark)
(writeKittyConfig "light-colors.conf" cfg.colors.light)
];
};
# Shell scripts for changing Kitty colors
term-background = pkgs.writeShellScriptBin "term-background" ''
# Accepts arguments "light" or "dark". If shell is running in a Kitty window set the colors.
if [ -n "$KITTY_WINDOW_ID" ]; then
kitty @ --to $KITTY_LISTEN_ON set-colors --all --configured \
${kitty-colors}/"$1"-colors.conf &
fi
'';
term-light = pkgs.writeShellScriptBin "term-light" ''
${term-background}/bin/term-background light
'';
term-dark = pkgs.writeShellScriptBin "term-dark" ''
${term-background}/bin/term-background dark
'';
in {
options.programs.kitty.extras = {
colors = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
When enable, commands <command>term-dark</command> and <command>term-light</command> will
toggle between your dark and a light colors.
<command>term-background</command> which accepts one argument (the value of which should
be <literal>dark</literal> or <literal>light</literal>) is also avaible.
(Note that the Kitty setting <literal>allow_remote_control = true</literal> is set to
enable this functionality.)
'';
};
dark = mkOption {
type = with types; attrsOf str;
default = {};
description = ''
Kitty color settings for dark background colorscheme.
'';
};
light = mkOption {
type = with types; attrsOf str;
default = {};
description = ''
Kitty color settings for light background colorscheme.
'';
};
common = mkOption {
type = with types; attrsOf str;
default = {};
description = ''
Kitty color settings that the light and dark background colorschemes share.
'';
};
default = mkOption {
type = types.enum [ "dark" "light" ];
default = "dark";
description = ''
The colorscheme Kitty opens with.
'';
};
};
useSymbolsFromNerdFont = mkOption {
type = types.str;
default = "";
example = "JetBrainsMono Nerd Font";
description = ''
NerdFont patched fonts frequently suffer from rendering issues in terminals. To mitigate
this, we can use a non-NerdFont with Kitty and use the <literal>symbol_map</literal> setting
to tell Kitty to only use a NerdFont for NerdFont symbols.
Set this option the name of an installed NerdFont (the same name you'd use in the
<literal>font_family</literal> setting), to enable this feature.
'';
};
};
config = mkIf config.programs.kitty.enable {
home.packages = mkIf cfg.colors.enable [
term-light
term-dark
term-background
];
programs.kitty.settings = optionalAttrs cfg.colors.enable (
cfg.colors.common // cfg.colors.${cfg.colors.default} // {
allow_remote_control = "yes";
listen_on = "unix:/tmp/mykitty";
}
) // optionalAttrs (cfg.useSymbolsFromNerdFont != "") {
# https://github.com/ryanoasis/nerd-fonts/wiki/Glyph-Sets-and-Code-Points
symbol_map = "U+E5FA-U+E62B,U+E700-U+E7C5,U+F000-U+F2E0,U+E200-U+E2A9,U+F500-U+FD46,U+E300-U+E3EB,U+F400-U+F4A8,U+2665,U+26a1,U+F27C,U+E0A3,U+E0B4-U+E0C8,U+E0CA,U+E0CC-U+E0D2,U+E0D4,U+23FB-U+23FE,U+2B58,U+F300-U+F313,U+E000-U+E00D ${cfg.useSymbolsFromNerdFont}";
};
xdg.configFile."kitty/macos-launch-services-cmdline" =
mkIf (pkgs.stdenv.isDarwin && cfg.colors.enable) { text = "--listen-on unix:/tmp/mykitty"; };
};
}