Fonts: Difference between revisions
Nerd fonts: update to 25.05. |
Add section on patching nerd font into fonts |
||
| (5 intermediate revisions by 5 users not shown) | |||
| Line 13: | Line 13: | ||
noto-fonts | noto-fonts | ||
noto-fonts-cjk-sans | noto-fonts-cjk-sans | ||
noto-fonts-emoji | noto-fonts-color-emoji | ||
liberation_ttf | liberation_ttf | ||
fira-code | fira-code | ||
| Line 28: | Line 28: | ||
* <code>fonts.enableDefaultPackages</code>: when set to <code>true</code>, causes some "basic" fonts to be installed for reasonable Unicode coverage. Set to <code>true</code> if you are unsure about what languages you might end up reading. | * <code>fonts.enableDefaultPackages</code>: when set to <code>true</code>, causes some "basic" fonts to be installed for reasonable Unicode coverage. Set to <code>true</code> if you are unsure about what languages you might end up reading. | ||
* <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. | ||
=== Using fonts from TexLive === | |||
You can make use of all TeX/LaTeX fonts from CTAN and [[TexLive]] by passing | |||
the <code>fonts</code> attribute of your TexLive package to <code>fonts.package</code>: | |||
<syntaxhighlight lang="nix"> | |||
{ pkgs, ... }: | |||
let | |||
mytex = | |||
pkgs.texliveConTeXt.withPackages | |||
(ps: with ps; [ | |||
fandol | |||
libertinus-fonts | |||
]); | |||
in { | |||
fonts.packages = builtins.attrValues { | |||
inherit (pkgs) | |||
dejavu_fonts | |||
noto-fonts-cjk-serif | |||
noto-fonts-cjk-sans | |||
julia-mono; | |||
} ++ [ mytex.fonts ]; | |||
} | |||
</syntaxhighlight> | |||
=== Installing <code>nerdfonts</code> === | === Installing <code>nerdfonts</code> === | ||
| Line 33: | Line 57: | ||
Individual Nerd Fonts can be installed like so: | Individual Nerd Fonts can be installed like so: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix">fonts.packages = with pkgs; [ | ||
fonts.packages = with pkgs; [ | |||
nerd-fonts.fira-code | nerd-fonts.fira-code | ||
nerd-fonts.droid-sans-mono | nerd-fonts.droid-sans-mono | ||
]; | ];</syntaxhighlight> | ||
</syntaxhighlight> | |||
The available Nerd Font subpackages can be listed by searching for {{nixos:package|nerd-fonts.*}} on the [[Searching packages|NixOS Package Search]] or by running the following command: <pre>nix-instantiate --eval --expr " | The available Nerd Font subpackages can be listed by searching for {{nixos:package|nerd-fonts.*}} on the [[Searching packages|NixOS Package Search]] or by running the following command: <pre>nix-instantiate --eval --expr "with (import <nixpkgs> {}); lib.attrNames (lib.filterAttrs (_: lib.isDerivation) nerd-fonts)"</pre> | ||
==== Installing all <code>nerdfonts</code> ==== | ==== Installing all <code>nerdfonts</code> ==== | ||
| Line 46: | Line 68: | ||
Installing all fonts from the [https://www.nerdfonts.com/ Nerd Fonts repository] is as simple as adding all of the individual packages to the NixOS configuration. The following line will do exactly that, by searching for all derivations under the <code>nerd-font</code> attribute:{{file|/etc/nixos/configuration.nix|nix|<nowiki> | Installing all fonts from the [https://www.nerdfonts.com/ Nerd Fonts repository] is as simple as adding all of the individual packages to the NixOS configuration. The following line will do exactly that, by searching for all derivations under the <code>nerd-font</code> attribute:{{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
{ | { | ||
fonts.packages = builtins.filter lib.attrsets.isDerivation (builtins.attrValues pkgs.nerd-fonts) | fonts.packages = builtins.filter lib.attrsets.isDerivation (builtins.attrValues pkgs.nerd-fonts); | ||
} | } | ||
</nowiki>}} | </nowiki>}} | ||
=== Patching nerdfonts into fonts === | |||
Not all fonts have Nerd Fonts variants, thankfully you can easily patch them in yourself. | |||
{{File|3=(pkgs.scientifica.overrideAttrs (o: { | |||
nativeBuildInputs = [ pkgs.nerd-font-patcher ]; | |||
postInstall = '' | |||
mkdir -p $out/share/fonts/truetype/{scientifica,scientifica-nerd} | |||
mv $out/share/fonts/truetype/*.ttf $out/share/fonts/truetype/scientifica/ | |||
for f in $out/share/fonts/truetype/scientifica/*.ttf; do | |||
nerd-font-patcher --complete --outputdir $out/share/fonts/truetype/scientifica-nerd/ $f | |||
done | |||
''; | |||
}))|name=fonts.nix|lang=nix}} | |||
=== Let Fontconfig know the fonts within your Nix profile === | === Let Fontconfig know the fonts within your Nix profile === | ||
| Line 257: | Line 292: | ||
=== Noto Color Emoji doesn't render on Firefox === | === Noto Color Emoji doesn't render on Firefox === | ||
Enable <code>useEmbeddedBitmaps</code> in your | Enable <code>useEmbeddedBitmaps</code> in your NixOS configuration. | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
fonts.fontconfig.useEmbeddedBitmaps = true; | fonts.fontconfig.useEmbeddedBitmaps = true; | ||