Fonts: Difference between revisions

ZhX589 (talk | contribs)
Marked this version for translation
DHCP (talk | contribs)
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="bash">font=$(nix-build --no-out-link '<nixpkgs>' -A source-code-pro)/share/fonts/opentype/SourceCodePro-Regular.otf
<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="bash">
<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="bash">
<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="bash">
<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="bash">
<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 ];
system.fsPackages = [ pkgs.bindfs ];
  fileSystems = let
fileSystems = let
    mkRoSymBind = path: {
  mkRoSymBind = path: {
      device = path;
    device = path;
      fsType = "fuse.bindfs";
    fsType = "fuse.bindfs";
      options = [ "ro" "resolve-symlinks" "x-gvfs-hide" ];
    options = [ "ro" "resolve-symlinks" "x-gvfs-hide" ];
    };
  };
    fontsPkgs = config.fonts.packages ++ (with pkgs; [
  fontsPkgs = config.fonts.packages ++ (with pkgs; [
        # Add your cursor themes and icon packages here
      # Add your cursor themes and icon packages here
        bibata-cursors
      bibata-cursors
        gnome-themes-extra
      gnome-themes-extra
        # etc.
      # etc.
      ]);
    ]);
    x11Fonts = pkgs.runCommand "X11-fonts"
  x11Fonts = pkgs.runCommand "X11-fonts"
      {
    {
        preferLocalBuild = true;
      preferLocalBuild = true;
        nativeBuildInputs = with pkgs; [
      nativeBuildInputs = with pkgs; [
          gzip
        gzip
          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
         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");
      mkdir -p "$out/share/fonts"
     "/usr/share/fonts" = mkRoSymBind (x11Fonts + "/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-->
<!--T:69-->
fonts.packages = with pkgs; [
nts.packages = with pkgs; [
    noto-fonts
  noto-fonts
    noto-fonts-color-emoji
  noto-fonts-color-emoji
    noto-fonts-cjk-sans
  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>