kitty: make extraConfig obey mkOrder

this change makes kitty.extraConfig obey the lib.mkOrder function so
that text can be inserted at the right place.
This commit is contained in:
Ivan Kirilov Dimitrov
2025-05-28 22:17:42 +02:00
committed by Austin Horstman
parent 115344f32b
commit ad88262f06
6 changed files with 104 additions and 28 deletions

View File

@@ -12,6 +12,8 @@ let
mkOption
optionalString
types
mkMerge
mkOrder
;
cfg = config.programs.kitty;
@@ -275,32 +277,37 @@ in
home.packages = [ cfg.package ] ++ optionalPackage cfg.font;
programs.kitty.extraConfig = mkMerge [
(mkIf (cfg.font != null) (
mkOrder 510 ''
font_family ${cfg.font.name}
${optionalString (cfg.font.size != null) "font_size ${toString cfg.font.size}"}
''
))
(mkIf (cfg.themeFile != null) (
mkOrder 520 ''
include ${pkgs.kitty-themes}/share/kitty-themes/themes/${cfg.themeFile}.conf
''
))
(mkIf (cfg.shellIntegration.mode != null) (
mkOrder 530 ''
# Shell integration is sourced and configured manually
shell_integration ${cfg.shellIntegration.mode}
''
))
(mkOrder 540 (toKittyConfig cfg.settings))
(mkOrder 550 (toKittyActionAliases cfg.actionAliases))
(mkOrder 560 (toKittyKeybindings cfg.keybindings))
(mkOrder 570 (toKittyEnv cfg.environment))
];
xdg.configFile."kitty/kitty.conf" =
{
text =
''
# Generated by Home Manager.
# See https://sw.kovidgoyal.net/kitty/conf.html
''
+ lib.concatStringsSep "\n" [
(optionalString (cfg.font != null) ''
font_family ${cfg.font.name}
${optionalString (cfg.font.size != null) "font_size ${toString cfg.font.size}"}
'')
(optionalString (cfg.themeFile != null) ''
include ${pkgs.kitty-themes}/share/kitty-themes/themes/${cfg.themeFile}.conf
'')
(optionalString (cfg.shellIntegration.mode != null) ''
# Shell integration is sourced and configured manually
shell_integration ${cfg.shellIntegration.mode}
'')
(toKittyConfig cfg.settings)
(toKittyActionAliases cfg.actionAliases)
(toKittyKeybindings cfg.keybindings)
(toKittyEnv cfg.environment)
cfg.extraConfig
];
text = ''
# Generated by Home Manager.
# See https://sw.kovidgoyal.net/kitty/conf.html
${cfg.extraConfig}
'';
}
// lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
onChange = ''

View File

@@ -2,4 +2,5 @@
kitty-example-settings = ./example-settings.nix;
kitty-theme-to-themeFile = ./theme-to-themeFile.nix;
kitty-null-shellIntegration = ./null-shellIntegration.nix;
kitty-example-mkOrder = ./example-mkOrder.nix;
}

View File

@@ -0,0 +1,23 @@
# Generated by Home Manager.
# See https://sw.kovidgoyal.net/kitty/conf.html
font_family DejaVu Sans
font_size 8
# Shell integration is sourced and configured manually
shell_integration no-rc
include ~/.cache/wal/colors-kitty.conf
background_opacity 0.500000
enable_audio_bell no
scrollback_lines 10000
update_check_interval 0
action_alias launch_tab launch --cwd=current --type=tab
action_alias launch_window launch --cwd=current --type=os-window
map ctrl+c copy_or_interrupt
map ctrl+f>2 set_font_size 20
env LS_COLORS=1

View File

@@ -0,0 +1,49 @@
{ lib, pkgs, ... }:
{
config = {
programs.kitty = {
enable = true;
darwinLaunchOptions = lib.mkIf pkgs.stdenv.hostPlatform.isDarwin [
"--single-instance"
"--directory=/tmp/my-dir"
"--listen-on=unix:/tmp/my-socket"
];
settings = {
scrollback_lines = 10000;
enable_audio_bell = false;
update_check_interval = 0;
background_opacity = 0.5;
};
font.name = "DejaVu Sans";
font.size = 8;
keybindings = {
"ctrl+c" = "copy_or_interrupt";
"ctrl+f>2" = "set_font_size 20";
};
actionAliases = {
"launch_tab" = "launch --cwd=current --type=tab";
"launch_window" = "launch --cwd=current --type=os-window";
};
environment = {
LS_COLORS = "1";
};
extraConfig = lib.mkOrder 535 ''
include ~/.cache/wal/colors-kitty.conf
'';
};
nmt.script = ''
assertFileExists home-files/.config/kitty/kitty.conf
assertFileContent \
home-files/.config/kitty/kitty.conf \
${./example-mkOrder-expected.conf}
'';
};
}

View File

@@ -3,7 +3,6 @@
font_family DejaVu Sans
font_size 8
# Shell integration is sourced and configured manually
shell_integration no-rc