Fonts: Difference between revisions

Loxodoromy (talk | contribs)
m typo
Kaya (talk | contribs)
Add section on patching nerd font into fonts
 
(3 intermediate revisions by 3 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 44: 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 ===