nixos: rework font options

This commit is contained in:
ooks-io 2024-12-10 19:11:52 +11:00
parent c9f7e6b53c
commit 1fa7ae2a66
6 changed files with 107 additions and 41 deletions

View file

@ -1,12 +1,15 @@
{ {
osConfig, osConfig,
pkgs, pkgs,
lib,
... ...
}: let }: let
inherit (osConfig.ooknet.appearance.fonts) monospace regular; inherit (osConfig.ooknet.appearance.fonts) monospace regular;
inherit (lib) optionals;
in { in {
fonts.fontconfig.enable = true; fonts.fontconfig.enable = true;
home.packages = [ home.packages =
[
monospace.package monospace.package
regular.package regular.package
@ -15,5 +18,6 @@ in {
pkgs.noto-fonts-emoji pkgs.noto-fonts-emoji
(pkgs.nerdfonts.override (pkgs.nerdfonts.override
{fonts = ["NerdFontsSymbolsOnly"];}) {fonts = ["NerdFontsSymbolsOnly"];})
]; ]
++ optionals (monospace.fallback != null) [monospace.fallback.package];
} }

View file

@ -94,7 +94,7 @@ in {
*/ */
'' ''
* { * {
font-family: "${fonts.monospace.family}:style=Medium"; font-family: "${fonts.monospace.family}";
font-size: ${toString fonts.monospace.size}px; font-size: ${toString fonts.monospace.size}px;
border: solid #${color.border.base}; border: solid #${color.border.base};
} }

View file

@ -4,15 +4,27 @@
hozen, hozen,
... ...
}: let }: let
inherit (osConfig.ooknet.appearance) fonts; inherit (osConfig.ooknet.appearance.fonts) monospace;
inherit (hozen) color; inherit (hozen) color;
inherit (lib) mkMerge mkIf; inherit (lib) mkMerge mkIf;
inherit (osConfig.ooknet.workstation) default; inherit (osConfig.ooknet.workstation) default;
mkFontConfig = font: style: let
mkFont = f: let
sizeAttr =
if f.bitmap
then "pixelsize"
else "size";
familyStyle = f.variants.${style} or f.variants.regular;
in "${familyStyle}:${sizeAttr}=${toString font.size}";
primary = mkFont font;
fallback =
if font.fallback != null
then ",${mkFont font.fallback}"
else "";
in "${primary}${fallback}";
cfg = osConfig.ooknet.workstation.programs.foot; cfg = osConfig.ooknet.workstation.programs.foot;
fontOptions = let
size = if fonts.monospace.bitmap then "pixelsize" else "size";
family = if fonts.monospace.bitmap then "${fonts.monospace.family}:style=Medium" else "${fonts.monospace.family}";
in "${family}:${size}${toString fonts.monospace.size}";
in { in {
config = mkMerge [ config = mkMerge [
(mkIf (cfg.enable || default.terminal == "foot") { (mkIf (cfg.enable || default.terminal == "foot") {
@ -22,16 +34,20 @@ in {
settings = { settings = {
main = { main = {
term = "xterm-256color"; term = "xterm-256color";
font = "${fonts.monospace.family}:style=Medium:pixelsize=${toString fonts.monospace.size}",${fonts.monospace.fallback.family}; font = mkFontConfig monospace "regular";
font-bold = "${fonts.monospace.family}:style=Medium:pixelsize=${toString fonts.monospace.size}"; font-bold = mkFontConfig monospace "bold";
font-italic = "${fonts.monospace.family}:style=Medium:pixelsize=${toString fonts.monospace.size}"; font-italic = mkFontConfig monospace "italic";
font-bold-italic = "${fonts.monospace.family}:style=Medium:pixelsize=${toString fonts.monospace.size}"; font-bold-italic = mkFontConfig monospace "boldItalic";
dpi-aware = "no"; dpi-aware =
if monospace.bitmap
then "no"
else "yes";
letter-spacing = "0"; letter-spacing = "0";
bold-text-in-bright = "palette-based"; bold-text-in-bright = "palette-based";
resize-delay-ms = "80"; resize-delay-ms = "80";
pad = "9x9 center"; pad = "9x9 center";
selection-target = "clipboard"; selection-target = "clipboard";
font-size-adjustment = "1px";
}; };
tweak = { tweak = {

View file

@ -1,12 +1,32 @@
{lib, ...}: let {lib, ...}: let
inherit (lib) mkOption; inherit (lib) mkOption;
inherit (lib.types) str package path int bool; inherit (lib.types) str package path int bool submodule nullOr;
mkFontOption = { mkVariantOption = {
regular = mkOption {
type = str;
default = "";
};
bold = mkOption {
type = str;
default = "";
};
italic = mkOption {
type = str;
default = "";
};
boldItalic = mkOption {
type = str;
default = "";
};
};
mkBaseFontOption = {
family = mkOption { family = mkOption {
type = str; type = str;
default = ""; default = "";
}; };
variants = mkVariantOption;
package = mkOption { package = mkOption {
type = package; type = package;
default = null; default = null;
@ -19,20 +39,14 @@
type = bool; type = bool;
default = false; default = false;
}; };
fallback = {
family = mkOption {
type = str;
default = "";
}; };
package = mkOption { mkFontOption =
type = package; mkBaseFontOption
// {
fallback = mkOption {
type = nullOr (submodule {options = mkBaseFontOption;});
default = null; default = null;
}; };
size = mkOption {
type = int;
default = null;
};
};
}; };
in { in {
# imports = [./palettes]; # imports = [./palettes];

View file

@ -13,17 +13,36 @@ in {
ooknet.appearance = { ooknet.appearance = {
fonts = { fonts = {
monospace = { monospace = {
family = "CozetteHiDpi"; bitmap = true;
package = pkgs.cozette; package = pkgs.monocraft;
size = 22; size = 18;
family = "Monocraft";
variants = {
regular = "Monocraft:style=Medium";
bold = "Monocraft:style=Medium";
italic = "Monocraft:style=Medium";
boldItalic = "Monocraft:style=Medium";
};
fallback = { fallback = {
family = "JetBrainsMono Nerd Font"; family = "JetBrainsMono NFM";
package = pkgs.nerfonts.override {fonts = ["JetBrainsMono"];}; variants = {
regular = "JetBrainsMono NFM:style=Regular";
bold = "JetBrainsMono NFM:style=Bold";
italic = "JetBrainsMono NFM:style=Italic";
boldItalic = "JetBrainsMono NFM:style=Bold Italic";
};
package = pkgs.nerdfonts.override {fonts = ["JetBrainsMono"];};
size = 18; size = 18;
}; };
}; };
regular = { regular = {
family = "Fira Sans"; family = "Fira Sans";
variants = {
regular = "Fira Sans:style=Regular";
bold = "Fira Sans:style=Bold";
italic = "Fira Sans:style=Italic";
boldItalic = "Fira Sans:style=Bold Italic";
};
package = pkgs.fira; package = pkgs.fira;
}; };
}; };

View file

@ -13,12 +13,25 @@ in {
ooknet.appearance = { ooknet.appearance = {
fonts = { fonts = {
monospace = { monospace = {
family = "JetBrainsMono Nerd Font";
package = pkgs.nerdfonts.override {fonts = ["JetBrainsMono"];}; package = pkgs.nerdfonts.override {fonts = ["JetBrainsMono"];};
size = 18;
family = "JetBrainsMono NF";
variants = {
regular = "JetBrainsMono NF:style=Regular";
bold = "JetBrainsMono NF:style=Bold";
italic = "JetBrainsMono NF:style=Italic";
boldItalic = "JetBrainsMono NF:style=Bold Italic";
};
}; };
regular = { regular = {
family = "Fira Sans";
package = pkgs.fira; package = pkgs.fira;
family = "Fira Sans";
variants = {
regular = "Fira Sans:style=Regular";
bold = "Fira Sans:style=Bold";
italic = "Fira Sans:style=Italic";
boldItalic = "Fira Sans:style=Bold Italic";
};
}; };
}; };