treewide: add hjem module for ghostty

This commit is contained in:
Anthony Rodriguez 2025-02-17 23:12:35 +01:00
parent b84f8374cd
commit 54ae0fdd92
Signed by: nezia
SSH key fingerprint: SHA256:R/ue1eTzTHUoo77lJD/3fSUsyL4AwvcHImU5BAZai+8
2 changed files with 163 additions and 70 deletions

View file

@ -6,95 +6,91 @@
}: let }: let
inherit (lib) mapAttrs mkIf mkMerge optionalAttrs removePrefix; inherit (lib) mapAttrs mkIf mkMerge optionalAttrs removePrefix;
inherit (config.local.systemVars) username; inherit (config.local.systemVars) username;
toINI = lib.generators.toINIWithGlobalSection {listsAsDuplicateKeys = true;};
styleCfg = config.local.style; styleCfg = config.local.style;
prefix = "ctrl+a"; prefix = "ctrl+a";
mkGhosttyTheme = palette: let mkGhosttyTheme = palette: let
colors = mapAttrs (_: value: removePrefix "#" value) palette; colors = mapAttrs (_: value: removePrefix "#" value) palette;
in { in
palette = [ with colors; {
"0=#${colors.base00}" base16 = {
"1=#${colors.base08}" palette = [
"2=#${colors.base0B}" "0=#${base00}"
"3=#${colors.base0A}" "1=#${base08}"
"4=#${colors.base0D}" "2=#${base0B}"
"5=#${colors.base0E}" "3=#${base0A}"
"6=#${colors.base0C}" "4=#${base0D}"
"7=#${colors.base05}" "5=#${base0E}"
"8=#${colors.base02}" "6=#${base0C}"
"9=#${colors.base08}" "7=#${base05}"
"10=#${colors.base0B}" "8=#${base02}"
"11=#${colors.base0A}" "9=#${base08}"
"12=#${colors.base0D}" "10=#${base0B}"
"13=#${colors.base0E}" "11=#${base0A}"
"14=#${colors.base0C}" "12=#${base0D}"
"15=#${colors.base07}" "13=#${base0E}"
"16=#${colors.base09}" "14=#${base0C}"
"17=#${colors.base0F}" "15=#${base07}"
"18=#${colors.base01}" "16=#${base09}"
"19=#${colors.base02}" "17=#${base0F}"
"20=#${colors.base04}" "18=#${base01}"
"21=#${colors.base06}" "19=#${base02}"
]; "20=#${base04}"
background = colors.base00; "21=#${base06}"
foreground = colors.base05; ];
cursor-color = colors.base06; background = base00;
selection-background = colors.base02; foreground = base05;
selection-foreground = colors.base05; cursor-color = base06;
}; selection-background = base02;
selection-foreground = base05;
};
};
in { in {
config = mkIf config.local.profiles.desktop.enable { config = mkIf config.local.profiles.desktop.enable {
hjem.users.${username} = { hjem.users.${username} = {
files = mkMerge [ programs.ghostty = mkMerge [
{ {
".config/ghostty/config".text = enable = true;
toINI settings = {
{ font-family = ["monospace" "Symbols Nerd Font"];
globalSection = { font-size = 14;
font-family = ["monospace" "Symbols Nerd Font"]; gtk-single-instance = true;
font-size = 14; gtk-adwaita = false;
gtk-single-instance = true; confirm-close-surface = false;
gtk-adwaita = false;
confirm-close-surface = false;
keybind = [ keybind = [
"${prefix}>c=new_tab" "${prefix}>c=new_tab"
"${prefix}>p=move_tab:-1" "${prefix}>p=move_tab:-1"
"${prefix}>n=move_tab:1" "${prefix}>n=move_tab:1"
"${prefix}>\\=new_split:right" "${prefix}>\\=new_split:right"
"${prefix}>-=new_split:down" "${prefix}>-=new_split:down"
"${prefix}>h=goto_split:left" "${prefix}>h=goto_split:left"
"${prefix}>j=goto_split:bottom" "${prefix}>j=goto_split:bottom"
"${prefix}>k=goto_split:top" "${prefix}>k=goto_split:top"
"${prefix}>l=goto_split:right" "${prefix}>l=goto_split:right"
"${prefix}>shift+h=resize_split:left,10" "${prefix}>shift+h=resize_split:left,10"
"${prefix}>shift+j=resize_split:down,10" "${prefix}>shift+j=resize_split:down,10"
"${prefix}>shift+k=resize_split:up,10" "${prefix}>shift+k=resize_split:up,10"
"${prefix}>shift+l=resize_split:right,11" "${prefix}>shift+l=resize_split:right,11"
"${prefix}>z=toggle_split_zoom" "${prefix}>z=toggle_split_zoom"
]; ];
adw-toolbar-style = "flat"; adw-toolbar-style = "flat";
gtk-tabs-location = "bottom"; gtk-tabs-location = "bottom";
gtk-wide-tabs = false; gtk-wide-tabs = false;
window-decoration = false; window-decoration = false;
linux-cgroup = "always"; linux-cgroup = "always";
}; };
};
} }
(optionalAttrs styleCfg.enable (optionalAttrs styleCfg.enable
{ {
".config/ghostty/config".text = toINI { settings.theme = "base16";
globalSection.theme = "base16"; themes.base16 = mkGhosttyTheme styleCfg.scheme.palette;
};
".config/ghostty/themes/base16".text = toINI {globalSection = mkGhosttyTheme styleCfg.scheme.palette;};
}) })
]; ];
packages = [pkgs.ghostty];
}; };
systemd.user.services.ghostty = { systemd.user.services.ghostty = {

View file

@ -0,0 +1,97 @@
{
config,
lib,
pkgs,
...
}: let
inherit (lib.attrsets) mapAttrs' nameValuePair;
inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) attrs attrsOf package;
toINI = lib.generators.toINIWithGlobalSection {listsAsDuplicateKeys = true;};
cfg = config.programs.ghostty;
mkThemes = themes:
mapAttrs'
(name: value:
nameValuePair
".config/ghostty/themes/${name}"
{
text = toINI {globalSection = value.${name};};
})
themes;
in {
options.programs.ghostty = {
enable = mkEnableOption "Ghostty";
package = mkOption {
type = package;
default = pkgs.ghostty;
description = ''
The Ghostty package to use.
'';
};
settings = mkOption {
type = attrs;
default = {};
example = {
theme = "example-theme";
font-size = 10;
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`.
Please reference https://ghostty.org/docs/config/reference for config options.
'';
};
themes = mkOption {
type = attrsOf attrs;
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"
];
background = "#303446";
foreground = "#c6d0f5";
cursor-color = "#f2d5cf";
cursor-text = "#c6d0f5";
selection-background = "#626880";
selection-foreground = "#c6d0f5";
};
};
description = ''
An attribute set of themes, with the key as the theme name.
Please reference https://ghostty.org/docs/features/theme for config options.
'';
};
};
config = lib.mkIf cfg.enable {
packages = [cfg.package];
files =
{
".config/ghostty/config".text = toINI {globalSection = cfg.settings;};
}
// mkThemes cfg.themes;
};
}