Fonts: Difference between revisions
m improved guidance on where to determine font names for nerdfonts |
m changed the example font configuration ('noto-fonts-cjk' has been renamed renamed to 'noto-fonts-cjk-sans') |
||
(15 intermediate revisions by 9 users not shown) | |||
Line 6: | Line 6: | ||
Despite looking like normal packages, simply adding these font packages to your <code>environment.systemPackages</code> won't make the fonts accessible to applications. To achieve that, put these packages in the <code>[https://search.nixos.org/options?channel=unstable&show=fonts.packages&from=0&size=50&sort=relevance&type=packages&query=fonts.packages fonts.packages]</code> NixOS options list instead. | Despite looking like normal packages, simply adding these font packages to your <code>environment.systemPackages</code> won't make the fonts accessible to applications. To achieve that, put these packages in the <code>[https://search.nixos.org/options?channel=unstable&show=fonts.packages&from=0&size=50&sort=relevance&type=packages&query=fonts.packages fonts.packages]</code> NixOS options list instead. | ||
''For example:'' | ''For example:'' | ||
Line 14: | Line 12: | ||
fonts.packages = with pkgs; [ | fonts.packages = with pkgs; [ | ||
noto-fonts | noto-fonts | ||
noto-fonts-cjk | noto-fonts-cjk-sans | ||
noto-fonts-emoji | noto-fonts-emoji | ||
liberation_ttf | liberation_ttf | ||
Line 31: | Line 29: | ||
* <code>fonts.enableGhostscriptFonts</code>: affects the <code>ghostscript</code> package. Ghostscript packages some URW fonts for the standard PostScript typefaces. If <code>true</code>, these fonts will be visible to GUI applications. You could set it to <code>true</code> if you want these fonts, but <code>gyre-fonts</code> (part of <code>fonts.enableDefaultPackages</code>) might be higher-quality depending on your judgement. | * <code>fonts.enableGhostscriptFonts</code>: affects the <code>ghostscript</code> package. Ghostscript packages some URW fonts for the standard PostScript typefaces. If <code>true</code>, these fonts will be visible to GUI applications. You could set it to <code>true</code> if you want these fonts, but <code>gyre-fonts</code> (part of <code>fonts.enableDefaultPackages</code>) might be higher-quality depending on your judgement. | ||
=== Installing | === Installing all nerdfonts === | ||
The <code>nerdfonts</code> package | The <code>nerdfonts</code> package includes all fonts from the [https://www.nerdfonts.com/ Nerd Fonts repository], making it quite large and resulting in a longer installation time. If you want to install the entire collection, add the following line to your system configuration:{{file|/etc/nixos/configuration.nix|nix|3=fonts.packages = with pkgs; [ nerdfonts ];}} | ||
=== Installing specific nerdfonts === | |||
If you only need a selection of fonts from the package, you can overwrite the font selection like so: | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
Line 40: | Line 42: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
This will cause NixOS to download only the [https://github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts/FiraCode Fira Code] and [https://github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts/DroidSansMono Droid Sans Mono] fonts from [https://github.com/ryanoasis/nerd-fonts nerd-fonts] instead of the whole package. The relevant names can be found by looking at the file | This will cause NixOS to download only the [https://github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts/FiraCode Fira Code] and [https://github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts/DroidSansMono Droid Sans Mono] fonts from [https://github.com/ryanoasis/nerd-fonts nerd-fonts] instead of the whole package. The relevant names can be found by looking [https://github.com/NixOS/nixpkgs/blob/8764d898c4f365d98ef77af140b32c6396eb4e02/pkgs/data/fonts/nerdfonts/shas.nix at the list of the nerdfonts names in this commit]. | ||
For configurations using later versions of Nixpkgs (after 25.05), individual Nerd Fonts packages can be installed like so:<syntaxhighlight lang="nix"> | |||
fonts.packages = with pkgs; [ | |||
nerd-fonts.fira-code | |||
nerd-fonts.droid-sans-mono | |||
]; | |||
</syntaxhighlight> | |||
=== Let Fontconfig know the fonts within your Nix profile === | |||
Nix inserts its user profile path into <code>$XDG_DATA_DIRS</code>, which Fontconfig by default doesn't look in. This cause graphical applications like KDE Plasma not able to recognize the fonts installed via <code>nix-env</code> or <code>nix profile</code>. | |||
To solve this, add the file <code>100-nix.conf</code> to your Fontconfig user configuration directory (usually <code>$XDG_CONFIG_HOME/fontconfig/conf.d</code>): | |||
<syntaxhighlight lang="xml"> | |||
<?xml version="1.0"?> | |||
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd"> | |||
<fontconfig> | |||
<!-- NIX_PROFILE is the path to your Nix profile. See Nix Reference Manual for details. --> | |||
<dir>NIX_PROFILE/lib/X11/fonts</dir> | |||
<dir>NIX_PROFILE/share/fonts</dir> | |||
</fontconfig> | |||
</syntaxhighlight> | |||
and run <code>fc-cache</code>. | |||
Alternatively, [https://nix-community.github.io/home-manager/options.xhtml#opt-fonts.fontconfig.enable enable Fontconfig configuration] in your Home Manager configuration. | |||
=== Imperative installation of user fonts === | === Imperative installation of user fonts === | ||
Line 138: | Line 164: | ||
=== Flatpak applications can't find system fonts === | === Flatpak applications can't find system fonts === | ||
To expose available fonts under <code>/run/current-system/sw/share/X11/fonts</code>, enable <code>fontDir</code> in your NixOS configuration. | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
fonts.fontDir.enable = true; | fonts.fontDir.enable = true; | ||
</syntaxhighlight> | </syntaxhighlight>You will then need to link/copy this folder to one of the Flatpak-supported locations - see below. | ||
==== | ==== Solution 1: Copy fonts to <code>$HOME/.local/share/fonts</code> ==== | ||
Create fonts directory <code>$HOME/.local/share/fonts</code> and copy system fonts with option <code>-L, --dereference</code> | Create fonts directory <code>$HOME/.local/share/fonts</code> and copy system fonts with option <code>-L, --dereference</code>. You will need to repeat this step whenever the fonts change.<syntaxhighlight lang="bash"> | ||
mkdir $HOME/.local/share/fonts && cp -L /run/current-system/sw/share/X11/fonts/* $HOME/.local/share/fonts/ | mkdir $HOME/.local/share/fonts && cp -L /run/current-system/sw/share/X11/fonts/* $HOME/.local/share/fonts/ | ||
</syntaxhighlight>Note: There is | </syntaxhighlight>Note: There is no need to grant flatpak applications access to <code>$HOME/.local/share/fonts</code>. | ||
Instead, if you do that, some applications (for example, steam) won't work.<blockquote>Internals: How it works? | Instead, if you do that, some applications (for example, steam) won't work.<blockquote>Internals: How it works? | ||
Line 163: | Line 189: | ||
</syntaxhighlight>Then flatpak application can read fonts from that to display contents correctly.</blockquote> | </syntaxhighlight>Then flatpak application can read fonts from that to display contents correctly.</blockquote> | ||
==== | ==== Solution 2: Symlink to system fonts at <code>$HOME/.local/share/fonts</code> ==== | ||
<blockquote>'''Note:''' this method doesn't work for some flatpak applications (for example, steam)! | <blockquote>'''Note:''' this method doesn't work for some flatpak applications (for example, steam)! | ||
Error: <syntaxhighlight lang="console"> | Error: <syntaxhighlight lang="console"> | ||
$ flatpak | $ flatpak run com.valvesoftware.Steam | ||
bwrap: Can't make symlink at /home/username/.local/share/fonts: File exists | bwrap: Can't make symlink at /home/username/.local/share/fonts: File exists | ||
</syntaxhighlight></blockquote>Create a symlink in <code>XDG_DATA_HOME/fonts</code> pointing to <code>/run/current-system/sw/share/X11/fonts</code>, e. g. | </syntaxhighlight></blockquote>Create a symlink in <code>XDG_DATA_HOME/fonts</code> pointing to <code>/run/current-system/sw/share/X11/fonts</code>, e. g. | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
ln -s /run/current-system/sw/share/X11/fonts ~/.local/share/fonts | mkdir $HOME/.local/share/fonts && ln -s /run/current-system/sw/share/X11/fonts ~/.local/share/fonts/ | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Now you have two options. | Now you have two options. | ||
===== Option 1: | ===== Option 1: Allow access to the fonts folder and <code>/nix/store</code> ===== | ||
By using the Flatpak CLI or the Flatseal Flatpak make the following directory available to all Flatpaks <code>$HOME/.local/share/fonts</code> and <code>$HOME/.icons</code> the appropriate commands for this are: | By using the Flatpak CLI or the Flatseal Flatpak make the following directory available to all Flatpaks <code>$HOME/.local/share/fonts</code> and <code>$HOME/.icons</code> the appropriate commands for this are: | ||
Line 183: | Line 209: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
And, because <code>~/.local/share/fonts</code> is linked to <code>/run/current-system/sw/share/X11/fonts</code>, which in turn is linked to content in <code>/nix/store</code>. | And, because <code>~/.local/share/fonts</code> is linked to <code>/run/current-system/sw/share/X11/fonts</code>, which in turn is linked to content in <code>/nix/store</code>. You need to grant flatpak applications access to the <code>/nix/store</code> directory, so that they can load fonts correctly. You may need to reboot for this to fully take effect. | ||
You need to grant flatpak applications access to the <code>/nix/store</code> directory, | |||
so that they can load fonts correctly. | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
flatpak --user override --filesystem=/nix/store:ro | flatpak --user override --filesystem=/nix/store:ro | ||
flatpak --user override --filesystem=/run/current-system/sw/share/X11/fonts:ro | |||
</syntaxhighlight> | </syntaxhighlight> | ||
===== Option 2: | ===== Option 2: Allow access to the WHOLE filesystem ===== | ||
Allow them access the WHOLE filesystem of yours: <code>All system files</code> in Flatseal or equivalently <code>filesystem=host</code> available to your application, the command for this is: | Allow them access the WHOLE filesystem of yours: <code>All system files</code> in Flatseal or equivalently <code>filesystem=host</code> available to your application, the command for this is: | ||
Line 200: | Line 225: | ||
It is important to keep in mind that some flatpak apps may refuse to launch if given certain permissions, such as the Steam flatpak. | It is important to keep in mind that some flatpak apps may refuse to launch if given certain permissions, such as the Steam flatpak. | ||
=== | ==== Solution 3: Configure bindfs for fonts/cursors/icons support ==== | ||
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 ]; | |||
fileSystems = let | fileSystems = let | ||
mkRoSymBind = path: { | mkRoSymBind = path: { | ||
Line 210: | Line 235: | ||
options = [ "ro" "resolve-symlinks" "x-gvfs-hide" ]; | options = [ "ro" "resolve-symlinks" "x-gvfs-hide" ]; | ||
}; | }; | ||
aggregated = pkgs.buildEnv { | |||
name = "system-fonts-and-icons"; | |||
paths = config.fonts.packages ++ (with pkgs; [ | |||
# Add your cursor themes and icon packages here | |||
bibata-cursors | |||
gnome.gnome-themes-extra | |||
# etc. | |||
]); | |||
pathsToLink = [ "/share/fonts" "/share/icons" ]; | |||
}; | }; | ||
in { | in { | ||
"/usr/share/ | "/usr/share/fonts" = mkRoSymBind "${aggregated}/share/fonts"; | ||
"/usr | "/usr/share/icons" = mkRoSymBind "${aggregated}/share/icons"; | ||
}; | }; | ||
fonts | fonts.packages = with pkgs; [ | ||
noto-fonts | |||
noto-fonts-emoji | |||
noto-fonts-cjk | |||
]; | |||
</syntaxhighlight> | |||
=== Noto Color Emoji doesn't render on Firefox === | |||
Enable <code>useEmbeddedBitmaps</code> in your NixOs configuration. | |||
<syntaxhighlight lang="nix"> | |||
fonts.fontconfig.useEmbeddedBitmaps = true; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 241: | Line 266: | ||
[[Category:Configuration]] | [[Category:Configuration]] | ||
[[Category:Desktop]] | [[Category:Desktop]] | ||
[[Category:Fonts]] |