ghostty: support nesting attrs

This makes the hjem ghostty module more RFC42 compliant, as it can now
map nested attribute sets one level deep (as per Ghostty's configuration
format).
This commit is contained in:
Anthony Rodriguez 2025-02-18 09:33:53 +01:00
parent 54ae0fdd92
commit d3bb2e0e57
Signed by: nezia
SSH key fingerprint: SHA256:R/ue1eTzTHUoo77lJD/3fSUsyL4AwvcHImU5BAZai+8
2 changed files with 76 additions and 66 deletions

View file

@ -15,30 +15,30 @@
in
with colors; {
base16 = {
palette = [
"0=#${base00}"
"1=#${base08}"
"2=#${base0B}"
"3=#${base0A}"
"4=#${base0D}"
"5=#${base0E}"
"6=#${base0C}"
"7=#${base05}"
"8=#${base02}"
"9=#${base08}"
"10=#${base0B}"
"11=#${base0A}"
"12=#${base0D}"
"13=#${base0E}"
"14=#${base0C}"
"15=#${base07}"
"16=#${base09}"
"17=#${base0F}"
"18=#${base01}"
"19=#${base02}"
"20=#${base04}"
"21=#${base06}"
];
palette = {
"0" = "#${base00}";
"1" = "#${base08}";
"2" = "#${base0B}";
"3" = "#${base0A}";
"4" = "#${base0D}";
"5" = "#${base0E}";
"6" = "#${base0C}";
"7" = "#${base05}";
"8" = "#${base02}";
"9" = "#${base08}";
"10" = "#${base0B}";
"11" = "#${base0A}";
"12" = "#${base0D}";
"13" = "#${base0E}";
"14" = "#${base0C}";
"15" = "#${base07}";
"16" = "#${base09}";
"17" = "#${base0F}";
"18" = "#${base01}";
"19" = "#${base02}";
"20" = "#${base04}";
"21" = "#${base06}";
};
background = base00;
foreground = base05;
cursor-color = base06;
@ -59,23 +59,23 @@ in {
gtk-adwaita = false;
confirm-close-surface = false;
keybind = [
"${prefix}>c=new_tab"
"${prefix}>p=move_tab:-1"
"${prefix}>n=move_tab:1"
keybind = {
"${prefix}>c" = "new_tab";
"${prefix}>p" = "move_tab:-1";
"${prefix}>n" = "move_tab:1";
"${prefix}>\\=new_split:right"
"${prefix}>-=new_split:down"
"${prefix}>h=goto_split:left"
"${prefix}>j=goto_split:bottom"
"${prefix}>k=goto_split:top"
"${prefix}>l=goto_split:right"
"${prefix}>shift+h=resize_split:left,10"
"${prefix}>shift+j=resize_split:down,10"
"${prefix}>shift+k=resize_split:up,10"
"${prefix}>shift+l=resize_split:right,11"
"${prefix}>z=toggle_split_zoom"
];
"${prefix}>\\" = "new_split:right";
"${prefix}>-" = "new_split:down";
"${prefix}>h" = "goto_split:left";
"${prefix}>j" = "goto_split:bottom";
"${prefix}>k" = "goto_split:top";
"${prefix}>l" = "goto_split:right";
"${prefix}>shift+h" = "resize_split:left,10";
"${prefix}>shift+j" = "resize_split:down,10";
"${prefix}>shift+k" = "resize_split:up,10";
"${prefix}>shift+l" = "resize_split:right,11";
"${prefix}>z" = "toggle_split_zoom";
};
adw-toolbar-style = "flat";
gtk-tabs-location = "bottom";

View file

@ -4,11 +4,21 @@
pkgs,
...
}: let
inherit (lib.attrsets) mapAttrs' nameValuePair;
inherit (lib.attrsets) isAttrs mapAttrs' mapAttrsToList nameValuePair;
inherit (lib.generators) mkKeyValueDefault mkValueStringDefault toINIWithGlobalSection;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) attrs attrsOf package;
toINI = lib.generators.toINIWithGlobalSection {listsAsDuplicateKeys = true;};
mkKeyValue = key: value:
if isAttrs value
# ghostty's configuration format supports (so far) one level of nested keys as key1=key2=value
then builtins.concatStringsSep "\n" (mapAttrsToList (k: v: "${key}=${k}=${v}") value)
else (mkKeyValueDefault {mkValueString = mkValueStringDefault {};} "=" key value);
toGhosttyConf = toINIWithGlobalSection {
listsAsDuplicateKeys = true;
inherit mkKeyValue;
};
cfg = config.programs.ghostty;
@ -18,7 +28,7 @@
nameValuePair
".config/ghostty/themes/${name}"
{
text = toINI {globalSection = value.${name};};
text = toGhosttyConf {globalSection = value.${name};};
})
themes;
in {
@ -37,10 +47,10 @@ in {
example = {
theme = "example-theme";
font-size = 10;
keybind = [
"ctrl+h=goto_split:left"
"ctrl+l=goto_split:right"
];
keybind = {
"ctrl+h" = "goto_split:left";
"ctrl+l" = "goto_split:right";
};
};
description = ''
The configuration converted to INI and written to `${config.directory}/.config/ghostty/config`.
@ -52,24 +62,24 @@ in {
default = {};
example = {
example-theme = {
palette = [
"0=#51576d"
"1=#e78284"
"2=#a6d189"
"3=#e5c890"
"4=#8caaee"
"5=#f4b8e4"
"6=#81c8be"
"7=#a5adce"
"8=#626880"
"9=#e67172"
"10=#8ec772"
"11=#d9ba73"
"12=#7b9ef0"
"13=#f2a4db"
"14=#5abfb5"
"15=#b5bfe2"
];
palette = {
"0" = "#51576d";
"1" = "#e78284";
"2" = "#a6d189";
"3" = "#e5c890";
"4" = "#8caaee";
"5" = "#f4b8e4";
"6" = "#81c8be";
"7" = "#a5adce";
"8" = "#626880";
"9" = "#e67172";
"10" = "#8ec772";
"11" = "#d9ba73";
"12" = "#7b9ef0";
"13" = "#f2a4db";
"14" = "#5abfb5";
"15" = "#b5bfe2";
};
background = "#303446";
foreground = "#c6d0f5";
@ -90,7 +100,7 @@ in {
packages = [cfg.package];
files =
{
".config/ghostty/config".text = toINI {globalSection = cfg.settings;};
".config/ghostty/config".text = toGhosttyConf {globalSection = cfg.settings;};
}
// mkThemes cfg.themes;
};