kitty: remove IFD

With this change the theme check happens at activation time. An
integration test is also added to verify the functionality.

Fixes #5110
This commit is contained in:
alejandro-angulo 2024-08-17 10:21:57 -07:00 committed by Robert Helgesson
parent 2cf3abce03
commit ecaed80b18
No known key found for this signature in database
GPG key ID: 96E745BD17AA17ED
8 changed files with 185 additions and 27 deletions

View file

@ -3,7 +3,6 @@
with lib;
let
cfg = config.programs.kitty;
eitherStrBoolInt = with types; either str (either bool int);
@ -57,6 +56,26 @@ let
'';
};
in {
imports = [
(mkChangedOptionModule [ "programs" "kitty" "theme" ] [
"programs"
"kitty"
"themeFile"
] (config:
let value = getAttrFromPath [ "programs" "kitty" "theme" ] config;
in if value != null then
(let
matching = filter (x: x.name == value) (builtins.fromJSON
(builtins.readFile
"${pkgs.kitty-themes}/share/kitty-themes/themes.json"));
in throwIf (length matching == 0)
"kitty-themes does not contain a theme named ${value}"
strings.removeSuffix ".conf"
(strings.removePrefix "themes/" (head matching).file))
else
null))
];
options.programs.kitty = {
enable = mkEnableOption "Kitty terminal emulator";
@ -100,16 +119,16 @@ in {
'';
};
theme = mkOption {
themeFile = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Apply a Kitty color theme. This option takes the friendly name of
any theme given by the command {command}`kitty +kitten themes`.
See <https://github.com/kovidgoyal/kitty-themes>
for more details.
Apply a Kitty color theme. This option takes the file name of a theme
in `kitty-themes`, without the `.conf` suffix. See
<https://github.com/kovidgoyal/kitty-themes/tree/master/themes> for a
list of themes.
'';
example = "Space Gray Eighties";
example = "SpaceGray_Eighties";
};
font = mkOption {
@ -146,11 +165,11 @@ in {
type = types.str;
default = "no-rc";
example = "no-cursor";
apply = (o:
apply = o:
let
modes = splitString " " o;
filtered = filter (m: m != "no-rc") modes;
in concatStringsSep " " (concatLists [ [ "no-rc" ] filtered ]));
in concatStringsSep " " (concatLists [ [ "no-rc" ] filtered ]);
description = ''
Set the mode of the shell integration. This accepts the same options
as the `shell_integration` option of Kitty. Note that
@ -184,24 +203,15 @@ in {
text = ''
# Generated by Home Manager.
# See https://sw.kovidgoyal.net/kitty/conf.html
'' + concatStringsSep "\n" ([
'' + concatStringsSep "\n" [
(optionalString (cfg.font != null) ''
font_family ${cfg.font.name}
${optionalString (cfg.font.size != null)
"font_size ${toString cfg.font.size}"}
'')
(optionalString (cfg.theme != null) ''
include ${pkgs.kitty-themes}/share/kitty-themes/${
let
matching = filter (x: x.name == cfg.theme) (builtins.fromJSON
(builtins.readFile
"${pkgs.kitty-themes}/share/kitty-themes/themes.json"));
in throwIf (length matching == 0)
"kitty-themes does not contain a theme named ${cfg.theme}"
(head matching).file
}
(optionalString (cfg.themeFile != null) ''
include ${pkgs.kitty-themes}/share/kitty-themes/themes/${cfg.themeFile}.conf
'')
''
# Shell integration is sourced and configured manually
@ -211,13 +221,23 @@ in {
(toKittyKeybindings cfg.keybindings)
(toKittyEnv cfg.environment)
cfg.extraConfig
]);
];
} // optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
onChange = ''
${pkgs.procps}/bin/pkill -USR1 -u $USER kitty || true
'';
};
home.activation.checkKittyTheme = mkIf (cfg.themeFile != null) (let
themePath =
"${pkgs.kitty-themes}/share/kitty-themes/themes/${cfg.themeFile}.conf";
in hm.dag.entryBefore [ "writeBoundary" ] ''
if [[ ! -f "${themePath}" ]]; then
errorEcho "kitty-themes does not contain the theme file ${themePath}!"
exit 1
fi
'');
xdg.configFile."kitty/macos-launch-services-cmdline" = mkIf
(cfg.darwinLaunchOptions != null && pkgs.stdenv.hostPlatform.isDarwin) {
text = concatStringsSep " " cfg.darwinLaunchOptions;