Fonts: Difference between revisions
m Updated Formating |
m fix link |
||
| (6 intermediate revisions by 4 users not shown) | |||
| Line 67: | Line 67: | ||
{ | { | ||
fonts.packages = builtins.filter lib.attrsets.isDerivation (builtins.attrValues pkgs.nerd-fonts); | fonts.packages = builtins.filter lib.attrsets.isDerivation (builtins.attrValues pkgs.nerd-fonts); | ||
} | |||
# or if you already have fonts.packages set | |||
{ | |||
fonts.packages = [ | |||
# ... some fonts | |||
] | |||
++ builtins.filter lib.attrsets.isDerivation (builtins.attrValues pkgs.nerd-fonts); | |||
} | } | ||
</nowiki>|name=/etc/nixos/configuration.nix|lang=nix}} | </nowiki>|name=/etc/nixos/configuration.nix|lang=nix}} | ||
| Line 110: | Line 119: | ||
fc-list -v | grep -i source | fc-list -v | grep -i source | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Install fonts in nix-shells === | |||
<code>fonts</code> is not available as set-valued option in <code>mkshell</code> (gives you an error because it tries to coerce an attribute set into a string). Instead, insert the following:<ref>https://programming.dev/post/32484220</ref> | |||
<syntaxhighlight lang="nix"> | |||
{pkgs ? import <nixpkgs> {} }: | |||
let | |||
fontsConf = pkgs.makeFontsConf { | |||
fontDirectories = [ | |||
# your needed fonts here, e.g.: | |||
pkgs.font-awesome | |||
pkgs.atkinson-hyperlegible-next | |||
]; | |||
}; | |||
in | |||
pkgs.mkShell { | |||
packages = with pkgs; [ | |||
# your font-dependent packages, e.g.: | |||
typst | |||
]; | |||
shellHook = '' | |||
export FONTCONFIG_FILE="${fontsConf}" | |||
''; | |||
} | |||
</syntaxhighlight> | |||
Then <code>typst fonts</code> finds the installed fonts in the nix-shell. | |||
== Configuring fonts == | == Configuring fonts == | ||
| Line 257: | Line 295: | ||
Alternatively, you can expose relevant packages directly under <code>/usr/share/...</code> paths. This will also enable Flatpak to use a custom cursor theme if you have one. This solution doesn't require <code>fonts.fontDir.enable</code> to be enabled.<syntaxhighlight lang="nix"> | Alternatively, you can expose relevant packages directly under <code>/usr/share/...</code> paths. This will also enable Flatpak to use a custom cursor theme if you have one. This solution doesn't require <code>fonts.fontDir.enable</code> to be enabled.<syntaxhighlight lang="nix"> | ||
system.fsPackages = [ pkgs.bindfs ]; | system.fsPackages = [ pkgs.bindfs ]; | ||
fileSystems = let | fileSystems = let | ||
mkRoSymBind = path: { | mkRoSymBind = path: { | ||
| Line 264: | Line 301: | ||
options = [ "ro" "resolve-symlinks" "x-gvfs-hide" ]; | options = [ "ro" "resolve-symlinks" "x-gvfs-hide" ]; | ||
}; | }; | ||
fontsPkgs = config.fonts.packages ++ (with pkgs; [ | |||
# Add your cursor themes and icon packages here | |||
bibata-cursors | |||
gnome.gnome-themes-extra | |||
# etc. | |||
]); | |||
x11Fonts = pkgs.runCommand "X11-fonts" | |||
{ | |||
preferLocalBuild = true; | |||
nativeBuildInputs = with pkgs; [ | |||
gzip | |||
xorg.mkfontscale | |||
xorg.mkfontdir | |||
]; | |||
} | |||
('' | |||
mkdir -p "$out/share/fonts" | |||
font_regexp='.*\.\(ttf\|ttc\|otb\|otf\|pcf\|pfa\|pfb\|bdf\)\(\.gz\)?' | |||
'' | |||
+ (builtins.concatStringsSep "\n" (builtins.map (pkg: '' | |||
find ${toString pkg} -regex "$font_regexp" \ | |||
-exec ln -sf -t "$out/share/fonts" '{}' \; | |||
'') fontsPkgs | |||
)) | |||
+ '' | |||
cd "$out/share/fonts" | |||
mkfontscale | |||
mkfontdir | |||
cat $(find ${pkgs.xorg.fontalias}/ -name fonts.alias) >fonts.alias | |||
''); | |||
aggregatedIcons = pkgs.buildEnv { | |||
name = "system-icons"; | |||
paths = fontsPkgs; | |||
pathsToLink = [ | |||
"/share/icons" | |||
]; | |||
}; | }; | ||
in { | in { | ||
"/usr/share/ | "/usr/share/icons" = mkRoSymBind (aggregatedIcons + "/share/icons"); | ||
"/usr/share/ | "/usr/share/fonts" = mkRoSymBind (x11Fonts + "/share/fonts"); | ||
}; | }; | ||
| Line 284: | Line 348: | ||
noto-fonts-cjk | noto-fonts-cjk | ||
]; | ]; | ||
</syntaxhighlight> | </syntaxhighlight>Note that font cache inside flatpak container may not be recreated after changes to fonts in <code>/usr/share/fonts</code>, because font cache seem to be relying on file timestamps that are missing in <code>/nix/store</code>. | ||
You can make sure that font directory is bind-mounted properly inside flatpak container by running <code>flatpak enter <instance> findmnt | grep /run/host/fonts</code>, or by running <code>flatpak enter <instance> ls -alh /run/host/fonts</code> and compare it to <code>ls -alh /usr/share/fonts</code>. | |||
If everything is mounted properly, but you still do not see fonts in flatpak app - force font cache recreation inside flatpak container: <code>flatpak run --command=fc-cache <application id> -f -v</code> | |||
=== Noto Color Emoji doesn't render on Firefox === | === Noto Color Emoji doesn't render on Firefox === | ||