Fonts: Difference between revisions
Marked this version for translation |
m style fixes :-) |
||
| Line 66: | Line 66: | ||
nerd-fonts.droid-sans-mono | nerd-fonts.droid-sans-mono | ||
];|name=/etc/nixos/configuration.nix|lang=nix}} | ];|name=/etc/nixos/configuration.nix|lang=nix}} | ||
<translate> | <translate> | ||
| Line 145: | Line 144: | ||
''Example'': Install <code>SourceCodePro-Regular</code>. | ''Example'': Install <code>SourceCodePro-Regular</code>. | ||
<syntaxhighlight lang= | <syntaxhighlight lang=console> | ||
cp $font ~/.local/share/fonts | $ font=$(nix-build --no-out-link '<nixpkgs>' -A source-code-pro)/share/fonts/opentype/SourceCodePro-Regular.otf | ||
fc-cache | $ cp $font ~/.local/share/fonts | ||
# Verify that the font has been installed | $ fc-cache | ||
fc-list -v | grep -i source | $ # Verify that the font has been installed | ||
$ fc-list -v | grep -i source | |||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate>=== Install fonts in nix-shells === <!--T:24--></translate> | <translate>=== Install fonts in nix-shells === <!--T:24--></translate> | ||
| Line 162: | Line 161: | ||
<!--T:26--> | <!--T:26--> | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{pkgs ? import <nixpkgs> {} }: | { pkgs ? import <nixpkgs> {} }: | ||
let | let | ||
fontsConf = pkgs.makeFontsConf { | fontsConf = pkgs.makeFontsConf { | ||
| Line 334: | Line 333: | ||
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= | <syntaxhighlight lang=console> | ||
mkdir $HOME/.local/share/fonts && 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> | ||
<translate><!--T:60--> Now you have two options.</translate> | <translate><!--T:60--> Now you have two options.</translate> | ||
| Line 347: | Line 346: | ||
</translate> | </translate> | ||
<syntaxhighlight lang= | <syntaxhighlight lang=console> | ||
flatpak --user override --filesystem=$HOME/.local/share/fonts:ro | $ flatpak --user override --filesystem=$HOME/.local/share/fonts:ro | ||
flatpak --user override --filesystem=$HOME/.icons:ro | $ flatpak --user override --filesystem=$HOME/.icons:ro | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<translate><!--T:63--> 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.</translate> | <translate><!--T:63--> 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.</translate> | ||
<syntaxhighlight lang= | <syntaxhighlight lang=console> | ||
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 | $ flatpak --user override --filesystem=/run/current-system/sw/share/X11/fonts:ro | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 365: | Line 364: | ||
</translate> | </translate> | ||
<syntaxhighlight lang= | <syntaxhighlight lang=console> | ||
flatpak --user override --filesystem=host | $ flatpak --user override --filesystem=host | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 377: | Line 376: | ||
<translate><!--T:68--> | <translate><!--T:68--> | ||
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"> | 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 | |||
mkRoSymBind = path: { | |||
device = path; | |||
fsType = "fuse.bindfs"; | |||
options = [ "ro" "resolve-symlinks" "x-gvfs-hide" ]; | |||
}; | |||
fontsPkgs = config.fonts.packages ++ (with pkgs; [ | |||
# Add your cursor themes and icon packages here | |||
bibata-cursors | |||
gnome-themes-extra | |||
# etc. | |||
]); | |||
x11Fonts = pkgs.runCommand "X11-fonts" | |||
{ | |||
preferLocalBuild = true; | |||
nativeBuildInputs = with pkgs; [ | |||
gzip | |||
mkfontdir | mkfontdir | ||
]; | ]; | ||
} | } | ||
('' | |||
mkdir -p "$out/share/fonts" | |||
"/ | font_regexp='.*\.\(ttf\|ttc\|otb\|otf\|pcf\|pfa\|pfb\|bdf\)\(\.gz\)?' | ||
'' | |||
+ (builtins.concatStringsSep "\n" (builtins.map (pkg: '' | |||
find ${toString pkg} -regex "$font_regexp" \ | |||
-exec ln -sf -t "$out/share/fonts" '{}' \; | |||
'') fontsPkgs | |||
)) | |||
+ '' | |||
cd "$out/share/fonts" | |||
mkfontscale | |||
mkfontdir | |||
cat $(find ${pkgs.font-alias}/ -name fonts.alias) >fonts.alias | |||
''); | |||
aggregatedIcons = pkgs.buildEnv { | |||
name = "system-icons"; | |||
paths = fontsPkgs; | |||
pathsToLink = [ | |||
"/share/icons" | |||
]; | |||
}; | }; | ||
in { | |||
"/usr/share/icons" = mkRoSymBind (aggregatedIcons + "/share/icons"); | |||
"/usr/share/fonts" = mkRoSymBind (x11Fonts + "/share/fonts"); | |||
}; | |||
<!--T:69--> | |||
nts.packages = with pkgs; [ | |||
noto-fonts | |||
noto-fonts-color-emoji | |||
noto-fonts-cjk-sans | |||
]; | |||
</syntaxhighlight>Note that font cache inside flatpak container may not be recreated after changes to fonts in <code>/usr/share/fonts</code>, because font cache seem to be relying on file timestamps that are missing in <code>/nix/store</code>. | </syntaxhighlight>Note that font cache inside flatpak container may not be recreated after changes to fonts in <code>/usr/share/fonts</code>, because font cache seem to be relying on file timestamps that are missing in <code>/nix/store</code>. | ||
</translate> | </translate> | ||