Fonts: Difference between revisions

Geb (talk | contribs)
m changed the example font configuration ('noto-fonts-cjk' has been renamed renamed to 'noto-fonts-cjk-sans')
m make it clearer what nix-instantiate is doing to filter out the nerdfonts
(One intermediate revision by one other user not shown)
Line 29: 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 all nerdfonts ===
=== Installing <code>nerdfonts</code> ===
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 ===
Individual Nerd Fonts can be installed like so:


If you only need a selection of fonts from the package, you can overwrite the font selection like so:
<syntaxhighlight lang="nix">fonts.packages = with pkgs; [
  nerd-fonts.fira-code
  nerd-fonts.droid-sans-mono
];</syntaxhighlight>


<syntaxhighlight lang="nix">
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>
fonts.packages = with pkgs; [
  (nerdfonts.override { fonts = [ "FiraCode" "DroidSansMono" ]; })
];
</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 [https://github.com/NixOS/nixpkgs/blob/8764d898c4f365d98ef77af140b32c6396eb4e02/pkgs/data/fonts/nerdfonts/shas.nix at the list of the nerdfonts names in this commit].
==== Installing all <code>nerdfonts</code> ====


For configurations using later versions of Nixpkgs (after 25.05), individual Nerd Fonts packages can be installed like so:<syntaxhighlight lang="nix">
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 = with pkgs; [
{
  nerd-fonts.fira-code
  fonts.packages = builtins.filter lib.attrsets.isDerivation (builtins.attrValues pkgs.nerd-fonts)
  nerd-fonts.droid-sans-mono
}
];
</nowiki>}}
</syntaxhighlight>


=== Let Fontconfig know the fonts within your Nix profile ===
=== Let Fontconfig know the fonts within your Nix profile ===