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,53 +6,53 @@
}: let
inherit (lib) mapAttrs mkIf mkMerge optionalAttrs removePrefix;
inherit (config.local.systemVars) username;
toINI = lib.generators.toINIWithGlobalSection {listsAsDuplicateKeys = true;};
styleCfg = config.local.style;
prefix = "ctrl+a";
mkGhosttyTheme = palette: let
colors = mapAttrs (_: value: removePrefix "#" value) palette;
in {
in
with colors; {
base16 = {
palette = [
"0=#${colors.base00}"
"1=#${colors.base08}"
"2=#${colors.base0B}"
"3=#${colors.base0A}"
"4=#${colors.base0D}"
"5=#${colors.base0E}"
"6=#${colors.base0C}"
"7=#${colors.base05}"
"8=#${colors.base02}"
"9=#${colors.base08}"
"10=#${colors.base0B}"
"11=#${colors.base0A}"
"12=#${colors.base0D}"
"13=#${colors.base0E}"
"14=#${colors.base0C}"
"15=#${colors.base07}"
"16=#${colors.base09}"
"17=#${colors.base0F}"
"18=#${colors.base01}"
"19=#${colors.base02}"
"20=#${colors.base04}"
"21=#${colors.base06}"
"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 = colors.base00;
foreground = colors.base05;
cursor-color = colors.base06;
selection-background = colors.base02;
selection-foreground = colors.base05;
background = base00;
foreground = base05;
cursor-color = base06;
selection-background = base02;
selection-foreground = base05;
};
};
in {
config = mkIf config.local.profiles.desktop.enable {
hjem.users.${username} = {
files = mkMerge [
programs.ghostty = mkMerge [
{
".config/ghostty/config".text =
toINI
{
globalSection = {
enable = true;
settings = {
font-family = ["monospace" "Symbols Nerd Font"];
font-size = 14;
gtk-single-instance = true;
@ -84,17 +84,13 @@ in {
linux-cgroup = "always";
};
};
}
(optionalAttrs styleCfg.enable
{
".config/ghostty/config".text = toINI {
globalSection.theme = "base16";
};
".config/ghostty/themes/base16".text = toINI {globalSection = mkGhosttyTheme styleCfg.scheme.palette;};
settings.theme = "base16";
themes.base16 = mkGhosttyTheme styleCfg.scheme.palette;
})
];
packages = [pkgs.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;
};
}