Skip to content

Commit

Permalink
feat(fonts): Add support for fallback fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
jalil-salame committed Dec 31, 2023
1 parent 5a7f3f1 commit 135d4a0
Show file tree
Hide file tree
Showing 29 changed files with 149 additions and 93 deletions.
16 changes: 8 additions & 8 deletions docs/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,25 @@ The default combination of fonts is:
```nix
{
stylix.fonts = {
serif = {
serif = [{
package = pkgs.dejavu_fonts;
name = "DejaVu Serif";
};
}];
sansSerif = {
sansSerif = [{
package = pkgs.dejavu_fonts;
name = "DejaVu Sans";
};
}];
monospace = {
monospace = [{
package = pkgs.dejavu_fonts;
name = "DejaVu Sans Mono";
};
}];
emoji = {
emoji = [{
package = pkgs.noto-fonts-emoji;
name = "Noto Color Emoji";
};
}];
};
}
```
Expand Down
7 changes: 5 additions & 2 deletions modules/alacritty/hm.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{pkgs, config, lib, ... }:

with config.stylix.fonts;

let
inherit (config.stylix) fonts;
inherit (fonts) sizes;

monospace = builtins.head fonts.monospace;

themeFile = config.lib.stylix.colors {
templateRepo = config.lib.stylix.templates.base16-alacritty;
};
Expand Down
1 change: 0 additions & 1 deletion modules/avizo/hm.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{ config, lib, options, ... }:

with config.lib.stylix.colors;
with config.stylix.fonts;
let
aviOpacity = toString config.stylix.opacity.popups;
in
Expand Down
8 changes: 5 additions & 3 deletions modules/bemenu/hm.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{pkgs, config, lib, ... }:
{ pkgs, config, lib, ... }:

with config.lib.stylix.colors.withHashtag;
with config.stylix.fonts;
let
inherit (config.stylix) fonts;
inherit (fonts) sizes;
sansSerif = builtins.head fonts.sansSerif;
bemenuOpacity = lib.toHexString ((((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100));
in {
options.stylix.targets.bemenu = {
Expand Down Expand Up @@ -42,7 +44,7 @@ in {
"--scf '${base03}'"
"--ab '${if alternate then base00 else base01}'"
"--af '${if alternate then base04 else base05}'"
"--fn '${sansSerif.name} ${lib.optionalString (fontSize != null) (builtins.toString fontSize)}'"
"--fn '${sansSerif.name} ${lib.optionalString (fontSize != null) (builtins.toString fontSize)}'"
];
};
}
4 changes: 3 additions & 1 deletion modules/dunst/hm.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{ config, lib, ... }:

with config.lib.stylix.colors.withHashtag;
with config.stylix.fonts;
let
dunstOpacity = lib.toHexString ((((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100));
inherit (config.stylix) fonts;
inherit (fonts) sizes;
sansSerif = builtins.head sansSerif;
in {
options.stylix.targets.dunst.enable =
config.lib.stylix.mkEnableTarget "Dunst" true;
Expand Down
3 changes: 2 additions & 1 deletion modules/emacs/hm.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{ pkgs, config, lib, ... }:

with config.lib.stylix.colors.withHashtag;
with config.stylix.fonts;

let
inherit (config.stylix) fonts;
monospace = builtins.head fonts.monospace;
emacsOpacity = builtins.toString (builtins.ceil (config.stylix.opacity.applications * 100));
in
{
Expand Down
7 changes: 5 additions & 2 deletions modules/foot/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ in {
config.programs.foot.settings = lib.mkIf cfg.enable {
main = {
include = theme;
font =
with config.stylix.fonts;
font = let
inherit (config.stylix) fonts;
inherit (fonts) sizes;
monospace = builtins.head fonts.monospace;
in
"${monospace.name}:size=${toString sizes.terminal}";
dpi-aware = "no";
};
Expand Down
7 changes: 5 additions & 2 deletions modules/fuzzel/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ in {
border = "${base0D-hex}ff";
};

main = {
font = "${config.stylix.fonts.sansSerif.name}:size=${toString config.stylix.fonts.sizes.popups}";
main = let
inherit (config.stylix) fonts;
sansSerif = builtins.head fonts.sansSerif;
in {
font = "${sansSerif.name}:size=${toString fonts.sizes.popups}";
dpi-aware = "no";
};
};
Expand Down
8 changes: 7 additions & 1 deletion modules/gnome/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ with lib;
picture-uri-dark = "file://${config.stylix.image}";
};

"org/gnome/desktop/interface" = with config.stylix.fonts ; {
"org/gnome/desktop/interface" = let
inherit (config.stylix) fonts;
inherit (fonts) sizes;
serif = builtins.head fonts.serif;
sansSerif = builtins.head fonts.sansSerif;
monospace = builtins.head fonts.monospace;
in {
# We show the same colours regardless of this setting, and the quick
# settings tile is removed. The value is still used by Epiphany to
# request dark mode for websites which support it.
Expand Down
6 changes: 5 additions & 1 deletion modules/grub/nixos.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{ pkgs, config, lib, ... }:

with config.lib.stylix;
with config.stylix.fonts;
with config.lib.stylix.colors.withHashtag;

let
inherit (config.stylix) fonts;
inherit (fonts) sizes;
monospace = builtins.head fonts.monospace;
sansSerif = builtins.head fonts.sansSerif;

# Grub requires fonts to be converted to "PFF2 format"
# This function takes a font { name, package } and produces a .pf2 file
mkGrubFont = font:
Expand Down
11 changes: 7 additions & 4 deletions modules/gtk/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ in {
# programs.dconf.enable = true; required in system config
gtk = {
enable = true;
font = {
inherit (config.stylix.fonts.sansSerif) package name;
size = config.stylix.fonts.sizes.applications;
};
font = let
inherit (config.stylix) fonts;
sansSerif = builtins.head fonts.sansSerif;
in {
inherit (sansSerif) package name;
size = fonts.sizes.applications;
};
theme = {
package = pkgs.adw-gtk3;
name = "adw-gtk3";
Expand Down
4 changes: 2 additions & 2 deletions modules/i3/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ let
unfocused = base03;

fonts = let
fonts = config.stylix.fonts;
inherit (config.stylix) fonts;
in {
names = [ fonts.sansSerif.name ];
names = lib.catAttrs "name" fonts.sansSerif;
size = fonts.sizes.desktop * 1.0;
};

Expand Down
5 changes: 4 additions & 1 deletion modules/kde/hm.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{ pkgs, config, lib, ... }:

with config.stylix.fonts;
with config.lib.stylix.colors;

let
inherit (config.stylix) fonts;
inherit (fonts) sizes;
sansSerif = builtins.head fonts.sansSerif;
monospace = builtins.head fonts.monospace;
formatValue = value:
if builtins.isBool value
then if value then "true" else "false"
Expand Down
9 changes: 6 additions & 3 deletions modules/kitty/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ in {

config = lib.mkIf cfg.enable {
programs.kitty = {
font = {
inherit (config.stylix.fonts.monospace) package name;
size = config.stylix.fonts.sizes.terminal;
font = let
inherit (config.stylix) fonts;
monospace = builtins.head fonts.monospace;
in {
inherit (monospace) package name;
size = fonts.sizes.terminal;
};
settings.background_opacity = with config.stylix.opacity; "${builtins.toString terminal}";
extraConfig = ''
Expand Down
4 changes: 3 additions & 1 deletion modules/mako/hm.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{pkgs, config, lib, options, ... }:

with config.lib.stylix.colors.withHashtag;
with config.stylix.fonts;
let
inherit (config.stylix) fonts;
inherit(fonts) sizes;
sansSerif = builtins.head fonts.sansSerif;
makoOpacity = lib.toHexString ((((builtins.ceil (config.stylix.opacity.popups * 100)) * 255) / 100));
in {
options.stylix.targets.mako.enable =
Expand Down
6 changes: 5 additions & 1 deletion modules/qutebrowser/hm.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{ config, lib, ... }:

with config.stylix.fonts;
with config.lib.stylix.colors.withHashtag;

let
Expand All @@ -14,6 +13,11 @@ let
warning = base0E;
error = base08;

inherit (config.stylix) fonts;
inherit (fonts) sizes;
serif = builtins.head fonts.serif;
sansSerif = builtins.head fonts.sansSerif;
monospace = builtins.head fonts.monospace;
in {
options.stylix.targets.qutebrowser.enable =
config.lib.stylix.mkEnableTarget "Qutebrowser" true;
Expand Down
6 changes: 4 additions & 2 deletions modules/rofi/hm.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{ pkgs, config, lib, ... }:

with config.stylix.fonts;

let
inherit (config.stylix) fonts;
inherit (fonts) sizes;
monospace = builtins.head fonts.monospace;

rofiOpacity = builtins.toString (builtins.ceil (config.stylix.opacity.popups * 100));
finalString = ''
* { background: rgba ( {{base00-rgb-r}}, {{base00-rgb-g}}, {{base00-rgb-b}}, ${rofiOpacity} % );
Expand Down
9 changes: 6 additions & 3 deletions modules/sway/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ let
focused = base0A;
unfocused = base03;

fonts = {
names = [ config.stylix.fonts.sansSerif.name ];
size = config.stylix.fonts.sizes.desktop + 0.0;
fonts = let
inherit (config.stylix) fonts;
inherit (fonts) sizes;
in {
names = lib.catAttrs "name" fonts.sansSerif;
size = sizes.desktop + 0.0;
};

in {
Expand Down
7 changes: 4 additions & 3 deletions modules/sxiv/hm.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{ config, lib, ... }:

let
colors = config.lib.stylix.colors;
fonts = config.stylix.fonts;
inherit (config.lib.stylix) colors;
inherit (config.stylix) fonts;
sansSerif = builtins.head fonts.sansSerif;
in {
options.stylix.targets.sxiv.enable =
config.lib.stylix.mkEnableTarget "Sxiv" true;
Expand All @@ -12,7 +13,7 @@ in {
properties = {
"Sxiv.foreground" = "#${colors.base01}";
"Sxiv.background" = "#${colors.base04}";
"Sxiv.font" = "${fonts.sansSerif.name}-${toString fonts.sizes.applications}";
"Sxiv.font" = "${sansSerif.name}-${toString fonts.sizes.applications}";
};
};
};
Expand Down
6 changes: 4 additions & 2 deletions modules/vim/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ let
};

vimOptions = let
fonts = config.stylix.fonts;
inherit (config.stylix) fonts;
inherit (fonts) sizes;
monospace = builtins.head fonts.monospace;
in {
plugins = [ themePlugin ];
extraConfig = ''
set termguicolors
colorscheme base16-stylix
unlet g:colors_name
set guifont=${escape [" "] fonts.monospace.name}:h${toString fonts.sizes.terminal}
set guifont=${escape [" "] monospace.name}:h${toString sizes.terminal}
'';
};

Expand Down
5 changes: 3 additions & 2 deletions modules/vscode/hm.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{pkgs, config, lib, ... }:

with config.stylix.fonts;

let
inherit (config.stylix) fonts;
monospace = builtins.head fonts.monospace;

themeFile = config.lib.stylix.colors {
template = ./template.mustache;
extension = ".json";
Expand Down
6 changes: 5 additions & 1 deletion modules/waybar/hm.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{ config, lib, ... }:
with config.lib.stylix.colors.withHashtag;
with config.stylix.fonts;
let
inherit (config.stylix) fonts;
inherit (fonts) sizes;

sansSerif = builtins.head fonts.sansSerif;

colorlessModules = place: ''
.modules-${place} #workspaces button {
border-bottom: 3px solid transparent;
Expand Down
14 changes: 8 additions & 6 deletions modules/wezterm/hm.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{ config, lib, ... }:

let colors = config.lib.stylix.colors.withHashtag;
let
colors = config.lib.stylix.colors.withHashtag;

inherit (config.stylix) fonts;
inherit (fonts) sizes;

fontList = lib.strings.concatMapStringsSep ", " ({name,...}: "\"${name}\"") (fonts.monospace ++ fonts.emoji);
in {
options.stylix.targets.wezterm.enable =
config.lib.stylix.mkEnableTarget "wezterm" config.programs.wezterm.enable;
Expand Down Expand Up @@ -47,7 +53,6 @@ in {
};

xdg.configFile."wezterm/wezterm.lua".text = with colors;
with config.stylix.fonts;
lib.mkForce ''
-- Generated by Stylix
local wezterm = require("wezterm")
Expand All @@ -62,10 +67,7 @@ in {
-- See https://github.com/wez/wezterm/issues/2615
use_fancy_tab_bar = false,
color_scheme = "stylix",
font = wezterm.font_with_fallback {
"${monospace.name}",
"${emoji.name}",
},
font = wezterm.font_with_fallback { ${fontList} },
font_size = ${builtins.toString sizes.terminal},
window_background_opacity = ${
builtins.toString config.stylix.opacity.terminal
Expand Down
7 changes: 6 additions & 1 deletion modules/xfce/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
config.lib.stylix.mkEnableTarget "Xfce" false;

config = lib.mkIf config.stylix.targets.xfce.enable {
xfconf.settings = with config.stylix.fonts; {
xfconf.settings = let
inherit (config.stylix) fonts;
inherit (fonts) sizes;
sansSerif = builtins.head fonts.sansSerif;
monospace = builtins.head fonts.monospace;
in {
xfwm4 = {
"general/title_font" = "${sansSerif.name} ${toString sizes.desktop}";
};
Expand Down
Loading

0 comments on commit 135d4a0

Please sign in to comment.