Fonts: Difference between revisions
imported>Verhovsky No edit summary |
imported>Verhovsky No edit summary |
||
Line 23: | Line 23: | ||
=== Installing specific fonts from nerdfonts === | === Installing specific fonts from nerdfonts === | ||
You probably want to install some fonts from nerdfonts repository and not the | You probably want to install some fonts from the [https://www.nerdfonts.com/ nerdfonts] repository and not the entire repository (it takes a lot of time to install all the fonts). To achieve that on stable 20.03, you can use an overlay created by [https://github.com/lightdiscord/nix-nerd-fonts-overlay# LightDiscord]. Here is an example of how to use it: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ pkgs, ... }: | { pkgs, ... }: | ||
{ | { | ||
nixpkgs.overlays = [ (import ./nix-nerd-fonts-overlay/default.nix) ]; #Assuming you cloned the repository | nixpkgs.overlays = [ (import ./nix-nerd-fonts-overlay/default.nix) ]; # Assuming you cloned the repository to the same directory | ||
fonts.fonts = with pkgs; [ | fonts.fonts = with pkgs; [ | ||
nerd-fonts.firacode | nerd-fonts.firacode | ||
Line 36: | Line 36: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
This will cause NixOS to download only | This will cause NixOS to download only [https://github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts/FiraCode Fira Code], [https://github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts/JetBrainsMono Jetbrains Mono] 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. | ||
On unstable however, there's a built-in option that looks like | On unstable however, there's a built-in option that looks like this: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ pkgs, ... }: | { pkgs, ... }: | ||
Line 51: | Line 51: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
This will cause NixOS to download only | This will cause NixOS to download only Fira Code and Droid Sans Mono fonts from nerd-fonts instead of the whole package. | ||
=== Imperative installation of user fonts === | === Imperative installation of user fonts === | ||
Line 66: | Line 66: | ||
=== Set multiple fonts for different languages === | === Set multiple fonts for different languages === | ||
If you | If you want to use other languages alongside English, you may want to set appropriate fonts for each language in your whole OS. For example, a Persian speaker might want to use the [https://rastikerdar.github.io/vazir-font/ Vazir] font for Persian texts and the [https://design.ubuntu.com/font/ Ubuntu] font for English texts. Just put these lines into your <code>configuration.nix</code>: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
Line 103: | Line 103: | ||
=== Adding personal fonts to <code>~/.fonts</code> doesn't work === | === Adding personal fonts to <code>~/.fonts</code> doesn't work === | ||
The <code>~/.fonts</code> is being deprecated upstream<ref>https://lists.freedesktop.org/archives/fontconfig/2014-July/005269.html</ref>. It already | The <code>~/.fonts</code> directory is being deprecated upstream<ref>https://lists.freedesktop.org/archives/fontconfig/2014-July/005269.html</ref>. It already doesn't work in NixOS. | ||
The new preferred location is in <code>$XDG_DATA_HOME/fonts</code>, which for most users will resolve to <code>~/.local/share/fonts</code><ref>https://lists.freedesktop.org/archives/fontconfig/2014-July/005270.html</ref> | The new preferred location is in <code>$XDG_DATA_HOME/fonts</code>, which for most users will resolve to <code>~/.local/share/fonts</code><ref>https://lists.freedesktop.org/archives/fontconfig/2014-July/005270.html</ref> | ||
<hr /> | <hr /> |
Revision as of 19:09, 26 September 2020
Installing fonts on NixOS
NixOS has many font packages available, and you can easily search for your favourites on the NixOS packages site.
Despite looking like normal packages, simply adding these font packages to your environment.systemPackages
won't make the fonts accessible to applications. To achieve that, put these packages in the fonts.fonts
NixOS options list instead.
For example:
fonts.fonts = with pkgs; [
noto-fonts
noto-fonts-cjk
noto-fonts-emoji
liberation_ttf
fira-code
fira-code-symbols
mplus-outline-fonts
dina-font
proggyfonts
];
Installing specific fonts from nerdfonts
You probably want to install some fonts from the nerdfonts repository and not the entire repository (it takes a lot of time to install all the fonts). To achieve that on stable 20.03, you can use an overlay created by LightDiscord. Here is an example of how to use it:
{ pkgs, ... }:
{
nixpkgs.overlays = [ (import ./nix-nerd-fonts-overlay/default.nix) ]; # Assuming you cloned the repository to the same directory
fonts.fonts = with pkgs; [
nerd-fonts.firacode
nerd-fonts.jetbrainsmono
nerd-fonts.droidsansmono
];
}
This will cause NixOS to download only Fira Code, Jetbrains Mono and Droid Sans Mono fonts from nerd-fonts instead of the whole package.
On unstable however, there's a built-in option that looks like this:
{ pkgs, ... }:
{
fonts.fonts = with pkgs; [
(nerdfonts.override {
fonts = [ "FiraCode" "DroidSansMono" ];
})
];
}
This will cause NixOS to download only Fira Code and Droid Sans Mono fonts from nerd-fonts instead of the whole package.
Imperative installation of user fonts
This is useful for quick font experiments.
Example: Install SourceCodePro-Regular
.
font=$(nix-build --no-out-link '<nixpkgs>' -A source-code-pro)/share/fonts/opentype/SourceCodePro-Regular.otf
cp $font ~/.local/share/fonts
fc-cache
# Verify that the font has been installed
fc-list -v | grep -i source
Set multiple fonts for different languages
If you want to use other languages alongside English, you may want to set appropriate fonts for each language in your whole OS. For example, a Persian speaker might want to use the Vazir font for Persian texts and the Ubuntu font for English texts. Just put these lines into your configuration.nix
:
#----=[ Fonts ]=----#
fonts = {
enableDefaultFonts = true;
fonts = with pkgs; [
pkgs.ubuntu_font_family
# Persian Fonts
pkgs.vazir-fonts
];
fontconfig = {
penultimate.enable = false;
defaultFonts = {
serif = [ "Vazir" "Ubuntu" ];
sansSerif = [ "Vazir" "Ubuntu" ];
monospace = [ "Ubuntu" ];
};
};
};
Troubleshooting
What font names can be used in fonts.fontconfig.defaultFonts.monospace
?
Those that fontconfig will understand. This can be queried from a font file using fc-query
.
$ cd /nix/var/nix/profiles/system/sw/share/X11-fonts
$ fc-query DejaVuSans.ttf | grep '^\s\+family:' | cut -d'"' -f2
Adding personal fonts to ~/.fonts
doesn't work
The ~/.fonts
directory is being deprecated upstream[1]. It already doesn't work in NixOS.
The new preferred location is in $XDG_DATA_HOME/fonts
, which for most users will resolve to ~/.local/share/fonts
[2]