makeFontsConf: add impureFontDirectories argument

This commit is contained in:
Vincenzo Mantova 2023-11-26 19:41:02 +00:00 committed by Matthieu Coudron
parent ffe149b1c4
commit 9de711cf62
2 changed files with 26 additions and 15 deletions

View file

@ -1,16 +1,29 @@
{ runCommand, stdenv, lib, libxslt, fontconfig, dejavu_fonts, fontDirectories }:
{ runCommand, stdenv, lib, libxslt, fontconfig, dejavu_fonts, fontDirectories
, impureFontDirectories ? [
# nix user profile
"~/.nix-profile/lib/X11/fonts" "~/.nix-profile/share/fonts"
]
++ lib.optional stdenv.isDarwin "~/Library/Fonts"
++ [
# FHS paths for non-NixOS platforms
"/usr/share/fonts" "/usr/local/share/fonts"
]
# darwin paths
++ lib.optionals stdenv.isDarwin [ "/Library/Fonts" "/System/Library/Fonts" ]
# nix default profile
++ [ "/nix/var/nix/profiles/default/lib/X11/fonts" "/nix/var/nix/profiles/default/share/fonts" ] }:
runCommand "fonts.conf"
{
nativeBuildInputs = [ libxslt ];
buildInputs = [ fontconfig ];
inherit fontDirectories;
# Add a default font for non-nixos systems, <1MB and in nixos defaults.
fontDirectories = fontDirectories ++ [ dejavu_fonts.minimal ]
# further non-nixos fonts on darwin
++ lib.optionals stdenv.isDarwin [ "/System/Library/Fonts" "/Library/Fonts" "~/Library/Fonts" ];
impureFontDirectories = impureFontDirectories ++ [ dejavu_fonts.minimal ];
}
''
xsltproc --stringparam fontDirectories "$fontDirectories" \
--stringparam impureFontDirectories "$impureFontDirectories" \
--path ${fontconfig.out}/share/xml/fontconfig \
${./make-fonts-conf.xsl} ${fontconfig.out}/etc/fonts/fonts.conf \
> $out

View file

@ -15,6 +15,7 @@
<xsl:output method='xml' encoding="UTF-8" doctype-system="urn:fontconfig:fonts.dtd" />
<xsl:param name="fontDirectories" />
<xsl:param name="impureFontDirectories" />
<xsl:template match="/fontconfig">
@ -23,29 +24,26 @@
<!-- the first cachedir will be used to store the cache -->
<cachedir prefix="xdg">fontconfig</cachedir>
<xsl:text>&#0010;</xsl:text>
<!-- /var/cache/fontconfig is useful for non-nixos systems -->
<cachedir>/var/cache/fontconfig</cachedir>
<xsl:text>&#0010;</xsl:text>
<!-- system-wide config -->
<include ignore_missing="yes">/etc/fonts/conf.d</include>
<xsl:text>&#0010;</xsl:text>
<dir prefix="xdg">fonts</dir>
<xsl:text>&#0010;</xsl:text>
<xsl:for-each select="str:tokenize($fontDirectories)">
<dir><xsl:value-of select="." /></dir>
<xsl:text>&#0010;</xsl:text>
</xsl:for-each>
<!-- nix user profile -->
<dir>~/.nix-profile/lib/X11/fonts</dir>
<dir>~/.nix-profile/share/fonts</dir>
<!-- FHS paths for non-NixOS platforms -->
<dir>/usr/share/fonts</dir>
<dir>/usr/local/share/fonts</dir>
<!-- nix default profile -->
<dir>/nix/var/nix/profiles/default/lib/X11/fonts</dir>
<dir>/nix/var/nix/profiles/default/share/fonts</dir>
<xsl:for-each select="str:tokenize($impureFontDirectories)">
<dir><xsl:value-of select="." /></dir>
<xsl:text>&#0010;</xsl:text>
</xsl:for-each>
</fontconfig>