Fonts: Difference between revisions
m Updated Formating |
Previous hack does not work in case there are same font subpaths in multiple font packages, which seem to be occurring more likely in NixOS 25.11. This solution instead partly replicates fontDir logic and creates flat dir with all fonts symlinked. related discussion happened here: https://discourse.nixos.org/t/25-11-upgrade-error-two-given-paths-contain-a-conflicting-subpath/72972/14 |
||
| Line 257: | Line 257: | ||
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: { | ||
| Line 264: | Line 263: | ||
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 | |||
bibata-cursors | |||
gnome.gnome-themes-extra | |||
# etc. | |||
]); | |||
x11Fonts = pkgs.runCommand "X11-fonts" | |||
{ | |||
preferLocalBuild = true; | |||
nativeBuildInputs = with pkgs; [ | |||
gzip | |||
xorg.mkfontscale | |||
xorg.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.xorg.fontalias}/ -name fonts.alias) >fonts.alias | |||
''); | |||
aggregatedIcons = pkgs.buildEnv { | |||
name = "system-icons"; | |||
paths = fontsPkgs; | |||
pathsToLink = [ | |||
"/share/icons" | |||
]; | |||
}; | }; | ||
in { | in { | ||
"/usr/share/ | "/usr/share/icons" = mkRoSymBind (aggregatedIcons + "/share/icons"); | ||
"/usr/share/ | "/usr/share/fonts" = mkRoSymBind (x11Fonts + "/share/fonts"); | ||
}; | }; | ||