Significant progress on font customization

This commit is contained in:
Jan Bulthuis 2024-07-18 16:29:20 +02:00
parent 5f66c1c631
commit 472731c514
14 changed files with 271 additions and 38 deletions

View File

@ -232,29 +232,29 @@ in {
my-wqy-zenhei
my-wqy-microhei
my-wqy-bitmapsong
cozette
# cozette
#uw-ttyp0
#ucs-fonts
dina-font # Cool but too small :(
# dina-font # Cool but too small :(
#unifont # Replace with Kissinger2
#unifont_upper # Replace with Kissinger 2
(nerdfonts.override { fonts = ["NerdFontsSymbolsOnly"]; })
# (nerdfonts.override { fonts = ["NerdFontsSymbolsOnly"]; })
];
fonts.fontconfig.defaultFonts = {
serif = [
"DejaVu Serif"
];
sansSerif = [
"DejaVu Sans"
];
monospace = [
"Dina"
];
emoji = [
"CozetteVector"
"Noto Color Emoji"
];
};
# fonts.fontconfig.defaultFonts = {
# serif = [
# # "DejaVu Serif"
# ];
# sansSerif = [
# # "DejaVu Sans"
# ];
# monospace = [
# # "Dina"
# ];
# emoji = [
# # "Cozette Vector"
# # "Noto Color Emoji"
# ];
# };
fonts.fontconfig.localConf = ''
<alias>
<family>Dina</family>

View File

@ -7,6 +7,7 @@
./discord/default.nix
./feishin/default.nix
./firefox/default.nix
./fontconfig/default.nix
./obsidian/default.nix
./shell/bash.nix
./shell/fish.nix

View File

@ -0,0 +1,31 @@
{ lib, config, pkgs, ... }:
with lib;
let
cfg = config.modules.fontconfig;
in {
options.modules.fontconfig = {
enable = mkEnableOption "fontconfig";
};
config = mkIf cfg.enable {
fonts.fontconfig = {
enable = true;
defaultFonts = {
serif = [
config.theming.fonts.serif.name
];
sansSerif = [
config.theming.fonts.sansSerif.name
];
monospace = [
config.theming.fonts.monospace.name
];
emoji = [
config.theming.fonts.emoji.name
];
};
};
};
}

View File

@ -2,6 +2,8 @@
with lib;
let
cfg = config.theming;
# Stylix
stylix = pkgs.fetchFromGitHub {
owner = "danth";
@ -9,6 +11,69 @@ let
rev = "1ff9d37d27377bfe8994c24a8d6c6c1734ffa116";
sha256 = "0dz8h1ga8lnfvvmvsf6iqvnbvxrvx3qxi0y8s8b72066mqgvy8y5";
};
# Font module type
fontModule = types.submodule {
options = {
name = mkOption {
type = types.str;
description = "Font family name.";
};
package = mkOption {
type = types.anything;
description = "Font package";
};
recommendedSize = mkOption {
type = types.nullOr types.int;
default = null;
description = "Recommended size for displaying this font.";
};
fallbackFonts = mkOption {
type = types.listOf types.str;
default = [];
description = "Fallback fonts for specified font.";
};
};
};
fontModules = [
# Import all fonts
./fonts/cozette-vector.nix
./fonts/cozette.nix
./fonts/dejavu-sans.nix
./fonts/dejavu-serif.nix
./fonts/dina.nix
./fonts/fira-code.nix
./fonts/nerd-fonts-symbols.nix
./fonts/noto-color-emoji.nix
];
# Gather enabled fonts.
enabledFonts = [
cfg.fonts.serif.name
cfg.fonts.sansSerif.name
cfg.fonts.monospace.name
cfg.fonts.emoji.name
] ++ map (font: font.name) cfg.fonts.extraFonts;
# Flatten dependencies of fonts
fontPackages = converge (fonts:
listToAttrs (map (font: {
name = font;
value = true;
}) (
flatten (map (font:
[ font.name ]
++ cfg.fonts.pkgs.${font.name}.fallbackFonts
) (attrsToList fonts))
))
) (listToAttrs (map (font: {
name = font;
value = true;
}) enabledFonts));
# Convert set of fonts to list of packages
fontPackageList = map (font: cfg.fonts.pkgs.${font.name}.package) (attrsToList (traceVal fontPackages));
in {
imports = [
# Import all themes
@ -16,10 +81,15 @@ in {
./themes/catppuccin.nix
];
options.theming =
let
colors = config.theming.schemeColors;
in {
options.testing.test = mkOption {
type = types.anything;
default = traced;
description = "Wowzah";
};
options.modules.theming.enable = mkEnableOption "theming";
options.theming = let colors = config.theming.schemeColors; in {
darkMode = mkOption {
type = types.bool;
default = false;
@ -69,15 +139,67 @@ in {
description = "Margin of each window, actual space between windows will be twice this number.";
};
};
fonts = {
pkgs = mkOption {
type = types.attrsOf fontModule;
default = builtins.listToAttrs (map (module: {
name = module.name;
value = module;
}) (map (module: (import module) { inherit lib config pkgs; }) fontModules));
description = "All available font modules.";
};
serif = mkOption {
type = fontModule;
description = "Default serif font";
};
sansSerif = mkOption {
type = fontModule;
description = "Default sansSerif font.";
};
monospace = mkOption {
type = fontModule;
description = "Default monospace font.";
};
emoji = mkOption {
type = fontModule;
description = "Default emoji font.";
};
extraFonts = mkOption {
type = types.listOf fontModule;
default = [];
description = "Additional fonts to install.";
};
};
};
config = {
config = mkIf config.modules.theming.enable {
# Enable fontconfig
modules.fontconfig.enable = true;
# Install configured fonts
home.packages = fontPackageList;
# Enable stylix
# TODO: Move to own module
stylix = {
enable = true;
autoEnable = false;
base16Scheme = config.theming.colorScheme;
polarity = if config.theming.darkMode then "dark" else "light";
base16Scheme = cfg.colorScheme;
polarity = if cfg.darkMode then "dark" else "light";
fonts = {
serif = getAttrs [ "name" "package" ] cfg.fonts.serif;
sansSerif = getAttrs [ "name" "package" ] cfg.fonts.sansSerif;
monospace = getAttrs [ "name" "package" ] cfg.fonts.monospace;
emoji = getAttrs [ "name" "package" ] cfg.fonts.emoji;
};
};
};
}

View File

@ -0,0 +1,9 @@
{ pkgs, ... }:
{
name = "Cozette Vector";
package = pkgs.cozette;
recommendedSize = 9;
fallbackFonts = [
];
}

View File

@ -0,0 +1,10 @@
{ pkgs, ... }:
{
name = "Cozette";
package = pkgs.cozette;
recommendedSize = 9;
fallbackFonts = [
"Cozette Vector"
];
}

View File

@ -0,0 +1,8 @@
{ pkgs, ... }:
{
name = "DejaVu Sans";
package = pkgs.dejavu_fonts;
recommendedSize = 12;
fallbackFonts = [];
}

View File

@ -0,0 +1,8 @@
{ pkgs, ... }:
{
name = "DejaVu Serif";
package = pkgs.dejavu_fonts;
recommendedSize = 12;
fallbackFonts = [];
}

View File

@ -0,0 +1,10 @@
{ pkgs, ... }:
{
name = "Dina";
package = pkgs.dina-font;
recommendedSize = 9;
fallbackFonts = [
"Cozette"
];
}

View File

@ -0,0 +1,8 @@
{ pkgs, ... }:
{
name = "Fira Code";
package = pkgs.fira-code;
recommendedSize = 12;
fallbackFonts = [];
}

View File

@ -0,0 +1,8 @@
{ pkgs, ... }:
{
name = "Symbols Nerd Font Mono";
package = pkgs.nerdfonts.override { fonts = [ "NerdFontsSymbolsOnly" ]; };
recommendedSize = 12;
fallbackFonts = [];
}

View File

@ -0,0 +1,8 @@
{ pkgs, ... }:
{
name = "Noto Color Emoji";
package = pkgs.noto-fonts-color-emoji;
recommendedSize = 12;
fallbackFonts = [];
}

View File

@ -1,6 +1,6 @@
# How Jan likes his linux to be configured
{ ... }:
{ config, ... }:
{
imports = [
@ -11,11 +11,15 @@
# State version
home.stateVersion = "24.05";
# Enabled modules
modules = {
# Window manager
river.enable = true;
waylock.enable = true;
# Theming
theming.enable = true;
# Programs
feishin.enable = true;
firefox.enable = true;
@ -29,15 +33,21 @@
unfree.enable = true;
};
theming.themes.gruvbox = {
enable = false;
darkMode = false;
contrast = "hard";
};
# Theme configuration
theming = let fontpkgs = config.theming.fonts.pkgs; in {
# Fonts
fonts.serif = fontpkgs."DejaVu Serif";
fonts.sansSerif = fontpkgs."DejaVu Sans";
fonts.monospace = fontpkgs."Dina";
fonts.emoji = fontpkgs."Dina";
fonts.extraFonts = [
];
theming.themes.catppuccin = {
enable = true;
flavor = "latte";
# Color scheme
themes.catppuccin = {
enable = true;
flavor = "latte";
};
};
};
}

View File

@ -57,10 +57,10 @@ in {
# base16Scheme = "${pkgs.base16-schemes}/share/themes/gruvbox-dark-hard.yaml";
fonts = {
monospace = {
package = pkgs.dina-font;
name = "Dina";
};
# monospace = {
# package = pkgs.dina-font;
# name = "Dina";
# };
sizes = {
terminal = 9;