about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/fontconfig
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/libraries/fontconfig')
-rw-r--r--nixpkgs/pkgs/development/libraries/fontconfig/2.10.nix47
-rw-r--r--nixpkgs/pkgs/development/libraries/fontconfig/config-compat.patch28
-rw-r--r--nixpkgs/pkgs/development/libraries/fontconfig/default.nix79
-rw-r--r--nixpkgs/pkgs/development/libraries/fontconfig/make-fonts-cache.nix33
-rw-r--r--nixpkgs/pkgs/development/libraries/fontconfig/make-fonts-conf.nix17
-rw-r--r--nixpkgs/pkgs/development/libraries/fontconfig/make-fonts-conf.xsl59
6 files changed, 263 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/libraries/fontconfig/2.10.nix b/nixpkgs/pkgs/development/libraries/fontconfig/2.10.nix
new file mode 100644
index 000000000000..1d66735569d5
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/fontconfig/2.10.nix
@@ -0,0 +1,47 @@
+{ stdenv, fetchurl, pkgconfig, freetype, expat
+}:
+
+stdenv.mkDerivation rec {
+  name = "fontconfig-2.10.2";
+
+  src = fetchurl {
+    url = "http://fontconfig.org/release/${name}.tar.bz2";
+    sha256 = "0llraqw86jmw4vzv7inskp3xxm2gc64my08iwq5mzncgfdbfza4f";
+  };
+
+  outputs = [ "bin" "dev" "lib" "out" ]; # $out contains all the config
+
+  propagatedBuildInputs = [ freetype ];
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ expat ];
+
+  configureFlags = [
+    "--with-arch=${stdenv.hostPlatform.parsed.cpu.name}"
+    "--sysconfdir=/etc"
+    "--with-cache-dir=/var/cache/fontconfig"
+    "--disable-docs"
+    "--with-default-fonts="
+  ] ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
+    "--with-arch=${stdenv.hostPlatform.parsed.cpu.name}"
+  ];
+
+  enableParallelBuilding = true;
+
+  doCheck = true;
+
+  # Don't try to write to /var/cache/fontconfig at install time.
+  installFlags = "sysconfdir=$(out)/etc fc_cachedir=$(TMPDIR)/dummy RUN_FC_CACHE_TEST=false";
+
+  passthru = {
+    # Empty for backward compatibility, there was no versioning before 2.11
+    configVersion = "";
+  };
+
+  meta = with stdenv.lib; {
+    description = "A library for font customization and configuration";
+    homepage = http://fontconfig.org/;
+    license = licenses.bsd2; # custom but very bsd-like
+    platforms = platforms.all;
+    maintainers = [ maintainers.vcunat ];
+  };
+}
diff --git a/nixpkgs/pkgs/development/libraries/fontconfig/config-compat.patch b/nixpkgs/pkgs/development/libraries/fontconfig/config-compat.patch
new file mode 100644
index 000000000000..e86f08fb553c
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/fontconfig/config-compat.patch
@@ -0,0 +1,28 @@
+commit 05c6adf8104b4321d3a3716a7b9feb6bf223ed0c (HEAD, nixpkgs)
+Author: Vladimír Čunát <vcunat@gmail.com>
+Date:   Tue Nov 4 12:24:25 2014 +0100
+
+    add check for /etc/fonts/@configVersion@/fonts.conf
+    
+    It's checked between FONTCONFIG_FILE and the usual /etc/fonts/fonts.conf.
+    Also, hardcode /etc/fonts/fonts.conf to prevent accidental override.
+
+diff --git a/src/fccfg.c b/src/fccfg.c
+index 6377fd7..e9eb10a 100644
+--- a/src/fccfg.c
++++ b/src/fccfg.c
+@@ -2070,8 +2070,13 @@ FcConfigFilename (const FcChar8 *url)
+     if (!url || !*url)
+     {
+ 	url = (FcChar8 *) getenv ("FONTCONFIG_FILE");
++	if (!url) {
++	    static const FcChar8 *cfPath = "/etc/fonts/@configVersion@/fonts.conf";
++	    if (access (cfPath, R_OK) == 0)
++		url = cfPath;
++	}
+ 	if (!url)
+-	    url = (FcChar8 *) FONTCONFIG_FILE;
++	    url = (FcChar8 *) "/etc/fonts/fonts.conf";
+     }
+     file = 0;
+ 
diff --git a/nixpkgs/pkgs/development/libraries/fontconfig/default.nix b/nixpkgs/pkgs/development/libraries/fontconfig/default.nix
new file mode 100644
index 000000000000..186560ae101f
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/fontconfig/default.nix
@@ -0,0 +1,79 @@
+{ stdenv, substituteAll, fetchurl
+, pkgconfig, freetype, expat, libxslt, gperf, dejavu_fonts
+}:
+
+/** Font configuration scheme
+ - ./config-compat.patch makes fontconfig try the following root configs, in order:
+    $FONTCONFIG_FILE, /etc/fonts/${configVersion}/fonts.conf, /etc/fonts/fonts.conf
+    This is done not to override config of pre-2.11 versions (which just blow up)
+    and still use *global* font configuration at both NixOS or non-NixOS.
+ - NixOS creates /etc/fonts/${configVersion}/fonts.conf link to $out/etc/fonts/fonts.conf,
+    and other modifications should go to /etc/fonts/${configVersion}/conf.d
+ - See ./make-fonts-conf.xsl for config details.
+
+*/
+
+let
+  configVersion = "2.11"; # bump whenever fontconfig breaks compatibility with older configurations
+in
+stdenv.mkDerivation rec {
+  pname = "fontconfig";
+  version = "2.12.6";
+
+  src = fetchurl {
+    url = "http://fontconfig.org/release/${pname}-${version}.tar.bz2";
+    sha256 = "05zh65zni11kgnhg726gjbrd55swspdvhqbcnj5a5xh8gn03036g";
+  };
+
+  patches = [
+    (substituteAll {
+      src = ./config-compat.patch;
+      inherit configVersion;
+    })
+  ];
+
+  outputs = [ "bin" "dev" "lib" "out" ]; # $out contains all the config
+
+  propagatedBuildInputs = [ freetype ];
+  nativeBuildInputs = [ pkgconfig gperf libxslt ];
+  buildInputs = [ expat ];
+
+  configureFlags = [
+    "--with-arch=${stdenv.hostPlatform.parsed.cpu.name}"
+    "--with-cache-dir=/var/cache/fontconfig" # otherwise the fallback is in $out/
+    "--disable-docs"
+    # just <1MB; this is what you get when loading config fails for some reason
+    "--with-default-fonts=${dejavu_fonts.minimal}"
+  ] ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
+    "--with-arch=${stdenv.hostPlatform.parsed.cpu.name}"
+  ];
+
+  enableParallelBuilding = true;
+
+  doCheck = true;
+
+  # Don't try to write to /var/cache/fontconfig at install time.
+  installFlags = "fc_cachedir=$(TMPDIR)/dummy RUN_FC_CACHE_TEST=false";
+
+  postInstall = ''
+    cd "$out/etc/fonts"
+    xsltproc --stringparam fontDirectories "${dejavu_fonts.minimal}" \
+      --stringparam fontconfigConfigVersion "${configVersion}" \
+      --path $out/share/xml/fontconfig \
+      ${./make-fonts-conf.xsl} $out/etc/fonts/fonts.conf \
+      > fonts.conf.tmp
+    mv fonts.conf.tmp $out/etc/fonts/fonts.conf
+  '';
+
+  passthru = {
+    inherit configVersion;
+  };
+
+  meta = with stdenv.lib; {
+    description = "A library for font customization and configuration";
+    homepage = http://fontconfig.org/;
+    license = licenses.bsd2; # custom but very bsd-like
+    platforms = platforms.all;
+    maintainers = [ maintainers.vcunat ];
+  };
+}
diff --git a/nixpkgs/pkgs/development/libraries/fontconfig/make-fonts-cache.nix b/nixpkgs/pkgs/development/libraries/fontconfig/make-fonts-cache.nix
new file mode 100644
index 000000000000..2ee0af8cfc13
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/fontconfig/make-fonts-cache.nix
@@ -0,0 +1,33 @@
+{ runCommand, lib, fontconfig, fontDirectories }:
+
+runCommand "fc-cache"
+  rec {
+    buildInputs = [ fontconfig.bin ];
+    preferLocalBuild = true;
+    allowSubstitutes = false;
+    passAsFile = [ "fontDirs" ];
+    fontDirs = ''
+      <!-- Font directories -->
+      ${lib.concatStringsSep "\n" (map (font: "<dir>${font}</dir>") fontDirectories)}
+    '';
+  }
+  ''
+    export FONTCONFIG_FILE=$(pwd)/fonts.conf
+
+    cat > fonts.conf << EOF
+    <?xml version='1.0'?>
+    <!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
+    <fontconfig>
+      <include>${fontconfig.out}/etc/fonts/fonts.conf</include>
+      <cachedir>$out</cachedir>
+    EOF
+    cat "$fontDirsPath" >> fonts.conf
+    echo "</fontconfig>" >> fonts.conf
+
+    mkdir -p $out
+    fc-cache -sv
+
+    # This is not a cache dir in the normal sense -- it won't be automatically
+    # recreated.
+    rm -f "$out/CACHEDIR.TAG"
+  ''
diff --git a/nixpkgs/pkgs/development/libraries/fontconfig/make-fonts-conf.nix b/nixpkgs/pkgs/development/libraries/fontconfig/make-fonts-conf.nix
new file mode 100644
index 000000000000..b18d72e0a228
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/fontconfig/make-fonts-conf.nix
@@ -0,0 +1,17 @@
+{ runCommand, libxslt, fontconfig, dejavu_fonts, fontDirectories }:
+
+runCommand "fonts.conf"
+  {
+    nativeBuildInputs = [ libxslt ];
+    buildInputs = [ fontconfig ];
+    # Add a default font for non-nixos systems, <1MB and in nixos defaults.
+    fontDirectories = fontDirectories ++ [ dejavu_fonts.minimal ];
+  }
+  ''
+    xsltproc --stringparam fontDirectories "$fontDirectories" \
+      --stringparam fontconfig "${fontconfig.out}" \
+      --stringparam fontconfigConfigVersion "${fontconfig.configVersion}" \
+      --path ${fontconfig.out}/share/xml/fontconfig \
+      ${./make-fonts-conf.xsl} ${fontconfig.out}/etc/fonts/fonts.conf \
+      > $out
+  ''
diff --git a/nixpkgs/pkgs/development/libraries/fontconfig/make-fonts-conf.xsl b/nixpkgs/pkgs/development/libraries/fontconfig/make-fonts-conf.xsl
new file mode 100644
index 000000000000..dddbbe9e516b
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/fontconfig/make-fonts-conf.xsl
@@ -0,0 +1,59 @@
+<?xml version="1.0"?>
+
+<!--
+  This script copies the original fonts.conf from the fontconfig
+  distribution, but replaces all <dir> entries with the directories
+  specified in the $fontDirectories parameter.
+-->
+
+<xsl:stylesheet version="1.0"
+                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:str="http://exslt.org/strings"
+                extension-element-prefixes="str"
+                >
+
+  <xsl:output method='xml' encoding="UTF-8" doctype-system="fonts.dtd" />
+
+  <xsl:param name="fontDirectories" />
+  <xsl:param name="fontconfig" />
+  <xsl:param name="fontconfigConfigVersion" />
+
+  <xsl:template match="/fontconfig">
+
+    <fontconfig>
+      <xsl:apply-templates select="child::node()[name() != 'dir' and name() != 'cachedir' and name() != 'include']" />
+
+      <!-- the first cachedir will be used to store the cache -->
+      <cachedir prefix="xdg">fontconfig</cachedir>
+      <!-- /var/cache/fontconfig is useful for non-nixos systems -->
+      <cachedir>/var/cache/fontconfig</cachedir>
+
+      <!-- versioned system-wide config -->
+      <include ignore_missing="yes">/etc/fonts/<xsl:value-of select="$fontconfigConfigVersion" />/conf.d</include>
+
+      <dir prefix="xdg">fonts</dir>
+      <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>
+      <!-- nix default profile -->
+      <dir>/nix/var/nix/profiles/default/lib/X11/fonts</dir>
+      <dir>/nix/var/nix/profiles/default/share/fonts</dir>
+
+    </fontconfig>
+
+  </xsl:template>
+
+
+  <!-- New fontconfig >=2.11 doesn't like xml:space added by xsl:copy-of -->
+  <xsl:template match="node()|@*">
+    <xsl:copy>
+      <xsl:apply-templates select="node()|@*[name() != 'xml:space']"/>
+    </xsl:copy>
+  </xsl:template>
+
+</xsl:stylesheet>