Fonts: Difference between revisions

DHCP (talk | contribs)
m style fixes :-)
Simplified the Flatpak font/icon/theme fixes part and made them directly use the host font/icon/theme instead of manually declaring separate packages
Line 375: Line 375:
<translate>==== Solution 3: Configure bindfs for fonts/cursors/icons support ==== <!--T:67--></translate>
<translate>==== Solution 3: Configure bindfs for fonts/cursors/icons support ==== <!--T:67--></translate>
<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 host paths in <code>/run/current-system/sw/share/</code> directly under <code>/usr/share/...</code> paths. This will also enable Flatpak to use a custom cursor theme if you have one.<syntaxhighlight lang="nixos" line="1">
system.fsPackages = [ pkgs.bindfs ];
# flatpak-usr-fix.nix
fileSystems = let
{ pkgs, ... }:
   mkRoSymBind = path: {
 
     device = path;
{
  # Bind mounts fonts, icons and themes from
  # The /run/current-system/sw/share/* paths
  # to their /usr/share/* equivalents
 
  # Expose all fonts
  # under /run/current-system/sw/share/X11/fonts
  fonts.fontDir.enable = true;
 
  # Flatpak: Bind mounts /usr/share/* directories
  system.fsPackages = [ pkgs.bindfs ];
 
  # Fonts
   fileSystems."/usr/share/fonts" = {
     device = "/run/current-system/sw/share/X11/fonts";
     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; [
 
      # Add your cursor themes and icon packages here
   # Icons
      bibata-cursors
  fileSystems."/usr/share/icons" = {
      gnome-themes-extra
     device = "/run/current-system/sw/share/icons";
      # etc.
     fsType = "fuse.bindfs";
     ]);
    options = [
  x11Fonts = pkgs.runCommand "X11-fonts"
      "ro"
     {
      "resolve-symlinks"
      preferLocalBuild = true;
       "x-gvfs-hide"
      nativeBuildInputs = with pkgs; [
    ];
        gzip
  };
        mkfontdir
 
       ];
  # Themes
    }
  fileSystems."/usr/share/themes" = {
    (''
  device = "/run/current-system/sw/share/themes";
      mkdir -p "$out/share/fonts"
  fsType = "fuse.bindfs";
      font_regexp='.*\.\(ttf\|ttc\|otb\|otf\|pcf\|pfa\|pfb\|bdf\)\(\.gz\)?'
   options = [
    ''
     "ro"
    + (builtins.concatStringsSep "\n" (builtins.map (pkg: ''
     "resolve-symlinks"
        find ${toString pkg} -regex "$font_regexp" \
     "x-gvfs-hide"
          -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>