2022-01-23 01:32:58 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.kitty.extras;
|
|
|
|
|
|
|
|
# Create a Kitty config string from a Nix set
|
2022-01-23 23:50:34 +00:00
|
|
|
setToKittyConfig = with generators; toKeyValue { mkKeyValue = mkKeyValueDefault { } " "; };
|
2022-01-23 01:32:58 +00:00
|
|
|
|
|
|
|
# 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 = [
|
2022-07-26 04:22:16 +00:00
|
|
|
(writeKittyConfig "dark.conf" cfg.colors.dark)
|
|
|
|
(writeKittyConfig "light.conf" cfg.colors.light)
|
2022-01-23 01:32:58 +00:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
# Shell scripts for changing Kitty colors
|
|
|
|
term-background = pkgs.writeShellScriptBin "term-background" ''
|
2022-11-20 22:25:59 +00:00
|
|
|
# Accepts the name of a theme file in color-pkg
|
2022-07-26 04:22:16 +00:00
|
|
|
# If shell is running in a Kitty window set the colors.
|
2022-01-23 01:32:58 +00:00
|
|
|
if [ -n "$KITTY_WINDOW_ID" ]; then
|
|
|
|
kitty @ --to $KITTY_LISTEN_ON set-colors --all --configured \
|
2022-11-20 22:25:59 +00:00
|
|
|
${cfg.colors.color-pkg}/"$1".conf &
|
2022-01-23 01:32:58 +00:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
term-light = pkgs.writeShellScriptBin "term-light" ''
|
2022-11-20 22:25:59 +00:00
|
|
|
${term-background}/bin/term-background ${cfg.colors.light-name}
|
2022-01-23 01:32:58 +00:00
|
|
|
'';
|
|
|
|
term-dark = pkgs.writeShellScriptBin "term-dark" ''
|
2022-11-20 22:25:59 +00:00
|
|
|
${term-background}/bin/term-background ${cfg.colors.dark-name}
|
2022-01-23 01:32:58 +00:00
|
|
|
'';
|
2022-01-23 23:50:34 +00:00
|
|
|
in
|
|
|
|
{
|
2022-01-23 01:32:58 +00:00
|
|
|
|
|
|
|
options.programs.kitty.extras = {
|
|
|
|
colors = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2022-05-08 01:50:31 +00:00
|
|
|
When enabled, commands <command>term-dark</command> and <command>term-light</command> will
|
2022-01-23 01:32:58 +00:00
|
|
|
toggle between your dark and a light colors.
|
|
|
|
<command>term-background</command> which accepts one argument (the value of which should
|
2022-07-26 04:22:16 +00:00
|
|
|
be <literal>dark</literal> or <literal>light</literal>) is also available.
|
2022-01-23 01:32:58 +00:00
|
|
|
(Note that the Kitty setting <literal>allow_remote_control = true</literal> is set to
|
|
|
|
enable this functionality.)
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
dark = mkOption {
|
|
|
|
type = with types; attrsOf str;
|
|
|
|
description = ''
|
|
|
|
Kitty color settings for dark background colorscheme.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
light = mkOption {
|
|
|
|
type = with types; attrsOf str;
|
|
|
|
description = ''
|
|
|
|
Kitty color settings for light background colorscheme.
|
|
|
|
'';
|
|
|
|
};
|
2022-11-20 22:25:59 +00:00
|
|
|
|
|
|
|
color-pkg = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = kitty-colors;
|
|
|
|
description = "Package from which to load kitty colors.";
|
|
|
|
};
|
|
|
|
|
|
|
|
light-name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "light";
|
|
|
|
description = "The name to use for the light colorscheme.";
|
|
|
|
};
|
|
|
|
|
|
|
|
dark-name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "dark";
|
|
|
|
description = "The name to use for the dark colorscheme.";
|
|
|
|
};
|
2022-01-23 01:32:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-05-08 01:50:31 +00:00
|
|
|
fixIcon = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
When enabled, uses fileicon (should be installed via homebrew) to fixup the icon.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
appPath = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = null;
|
|
|
|
description = ''Path to kitty.app'';
|
|
|
|
};
|
|
|
|
|
|
|
|
iconPath = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = null;
|
|
|
|
description = ''Path to kitty icns'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-01-23 01:32:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf config.programs.kitty.enable {
|
|
|
|
|
|
|
|
home.packages = mkIf cfg.colors.enable [
|
|
|
|
term-light
|
|
|
|
term-dark
|
|
|
|
term-background
|
|
|
|
];
|
|
|
|
|
2022-11-08 02:39:25 +00:00
|
|
|
home.activation =
|
|
|
|
let
|
|
|
|
fileicon = "/opt/homebrew/bin/fileicon";
|
|
|
|
in
|
|
|
|
mkIf (pkgs.stdenv.isDarwin && cfg.fixIcon.enable) {
|
|
|
|
cleanupKittyIcon = lib.hm.dag.entryBetween [ "darwinApps" ] [ "writeBoundary" ] ''
|
|
|
|
if ${fileicon} test ${cfg.fixIcon.appPath};
|
|
|
|
then
|
|
|
|
$DRY_RUN_CMD sudo ${fileicon} rm ${cfg.fixIcon.appPath}
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
fixKittyIcon = lib.hm.dag.entryAfter [ "darwinApps" ] ''
|
|
|
|
$DRY_RUN_CMD sudo ${fileicon} set ${cfg.fixIcon.appPath} ${cfg.fixIcon.iconPath}
|
|
|
|
'';
|
|
|
|
};
|
2022-05-08 01:50:31 +00:00
|
|
|
|
2022-01-23 23:50:34 +00:00
|
|
|
programs.kitty.settings = optionalAttrs cfg.colors.enable
|
2022-11-20 22:07:02 +00:00
|
|
|
{
|
|
|
|
allow_remote_control = "yes";
|
|
|
|
listen_on = "unix:/tmp/mykitty";
|
|
|
|
} // optionalAttrs (cfg.useSymbolsFromNerdFont != "") {
|
2022-01-23 01:32:58 +00:00
|
|
|
|
|
|
|
# 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"; };
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-01-23 23:50:34 +00:00
|
|
|
}
|