Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ config, lib, stdenv, fetchurl, fetchpatch, pkg-config, libiconv 2, libintl, expat, zlib, libpng, pixman, fontconfig, freetype 3, x11Support? !stdenv.isDarwin, libXext, libXrender 4, gobjectSupport ? true, glib 5, xcbSupport ? x11Support, libxcb, xcbutil # no longer experimental since 1.12 6, libGLSupported ? lib.elem stdenv.hostPlatform.system lib.platforms.mesaPlatforms 7, glSupport ? x11Support && config.cairo.gl or (libGLSupported && stdenv.isLinux) 8, libGL # libGLU libGL is no longer a big dependency 9, pdfSupport ? true 10, darwin 11, testers 12}: 13 14let 15 inherit (lib) optional optionals; 16in stdenv.mkDerivation (finalAttrs: let 17 inherit (finalAttrs) pname version; 18in { 19 pname = "cairo"; 20 version = "1.16.0"; 21 22 src = fetchurl { 23 url = "https://cairographics.org/${if lib.mod (builtins.fromJSON (lib.versions.minor version)) 2 == 0 then "releases" else "snapshots"}/${pname}-${version}.tar.xz"; 24 sha256 = "0c930mk5xr2bshbdljv005j3j8zr47gqmkry3q6qgvqky6rjjysy"; 25 }; 26 27 patches = [ 28 # Fixes CVE-2018-19876; see Nixpkgs issue #55384 29 # CVE information: https://nvd.nist.gov/vuln/detail/CVE-2018-19876 30 # Upstream PR: https://gitlab.freedesktop.org/cairo/cairo/merge_requests/5 31 # 32 # This patch is the merged commit from the above PR. 33 (fetchpatch { 34 name = "CVE-2018-19876.patch"; 35 url = "https://gitlab.freedesktop.org/cairo/cairo/commit/6edf572ebb27b00d3c371ba5ae267e39d27d5b6d.patch"; 36 sha256 = "112hgrrsmcwxh1r52brhi5lksq4pvrz4xhkzcf2iqp55jl2pb7n1"; 37 }) 38 39 # Fix PDF output. 40 # https://gitlab.freedesktop.org/cairo/cairo/issues/342 41 (fetchpatch { 42 url = "https://gitlab.freedesktop.org/cairo/cairo/commit/5e34c5a9640e49dcc29e6b954c4187cfc838dbd1.patch"; 43 sha256 = "yCwsDUY7efVvOZkA6a0bPS+RrVc8Yk9bfPwWHeOjq5o="; 44 }) 45 46 # Fixes CVE-2020-35492; see https://github.com/NixOS/nixpkgs/issues/120364. 47 # CVE information: https://nvd.nist.gov/vuln/detail/CVE-2020-35492 48 # Upstream PR: https://gitlab.freedesktop.org/cairo/cairo/merge_requests/85 49 (fetchpatch { 50 name = "CVE-2020-35492.patch"; 51 includes = [ "src/cairo-image-compositor.c" ]; 52 url = "https://github.com/freedesktop/cairo/commit/78266cc8c0f7a595cfe8f3b694bfb9bcc3700b38.patch"; 53 sha256 = "048nzfz7rkgqb9xs0dfs56qdw7ckkxr87nbj3p0qziqdq4nb6wki"; 54 }) 55 56 # Workaround https://gitlab.freedesktop.org/cairo/cairo/-/issues/121 57 ./skip-configure-stderr-check.patch 58 59 # Fixes cairo crash on macOS Big Sur 60 # Upstream PR: https://gitlab.freedesktop.org/cairo/cairo/-/issues/420 61 (fetchpatch { 62 url = "https://gitlab.freedesktop.org/cairo/cairo/-/commit/e22d7212acb454daccc088619ee147af03883974.diff"; 63 sha256 = "sha256-8G98nsPz3MLEWPDX9F0jKgXC4hC4NNdFQLSpmW3ay2s="; 64 }) 65 66 # Fix unexpected color addition on grayscale images (usually text). 67 # Upstream fix: https://gitlab.freedesktop.org/cairo/cairo/-/merge_requests/114 68 # Can be removed after 1.18 release 69 (fetchpatch { 70 name = "fix-grayscale-anialias.patch"; 71 url = "https://gitlab.freedesktop.org/cairo/cairo/-/commit/4f4d89506f58a64b4829b1bb239bab9e46d63727.diff"; 72 sha256 = "sha256-mbTg67e7APfdELsuMAgXdY3xokWbGtHF7VDD5UyYqKM="; 73 }) 74 ]; 75 76 outputs = [ "out" "dev" "devdoc" ]; 77 outputBin = "dev"; # very small 78 separateDebugInfo = true; 79 80 nativeBuildInputs = [ 81 pkg-config 82 ]; 83 84 buildInputs = [ 85 libiconv 86 libintl 87 ] ++ optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ 88 CoreGraphics 89 CoreText 90 ApplicationServices 91 Carbon 92 ]); 93 94 propagatedBuildInputs = [ fontconfig expat freetype pixman zlib libpng ] 95 ++ optionals x11Support [ libXext libXrender ] 96 ++ optionals xcbSupport [ libxcb xcbutil ] 97 ++ optional gobjectSupport glib 98 ++ optional glSupport libGL 99 ; # TODO: maybe liblzo but what would it be for here? 100 101 configureFlags = [ 102 "--enable-tee" 103 ] ++ (if stdenv.isDarwin then [ 104 "--disable-dependency-tracking" 105 "--enable-quartz" 106 "--enable-quartz-font" 107 "--enable-quartz-image" 108 "--enable-ft" 109 ] else (optional xcbSupport "--enable-xcb" 110 ++ optional glSupport "--enable-gl" 111 ++ optional pdfSupport "--enable-pdf" 112 )) ++ optional (!x11Support) "--disable-xlib"; 113 114 preConfigure = 115 # On FreeBSD, `-ldl' doesn't exist. 116 lib.optionalString stdenv.isFreeBSD 117 '' for i in "util/"*"/Makefile.in" boilerplate/Makefile.in 118 do 119 cat "$i" | sed -es/-ldl//g > t 120 mv t "$i" 121 done 122 '' 123 + 124 '' 125 # Work around broken `Requires.private' that prevents Freetype 126 # `-I' flags to be propagated. 127 sed -i "src/cairo.pc.in" \ 128 -es'|^Cflags:\(.*\)$|Cflags: \1 -I${freetype.dev}/include/freetype2 -I${freetype.dev}/include|g' 129 substituteInPlace configure --replace strings $STRINGS 130 ''; 131 132 enableParallelBuilding = true; 133 134 doCheck = false; # fails 135 136 postInstall = lib.optionalString stdenv.isDarwin glib.flattenInclude; 137 138 passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; 139 140 meta = with lib; { 141 description = "A 2D graphics library with support for multiple output devices"; 142 longDescription = '' 143 Cairo is a 2D graphics library with support for multiple output 144 devices. Currently supported output targets include the X 145 Window System, Quartz, Win32, image buffers, PostScript, PDF, 146 and SVG file output. Experimental backends include OpenGL 147 (through glitz), XCB, BeOS, OS/2, and DirectFB. 148 149 Cairo is designed to produce consistent output on all output 150 media while taking advantage of display hardware acceleration 151 when available (e.g., through the X Render Extension). 152 ''; 153 homepage = "http://cairographics.org/"; 154 license = with licenses; [ lgpl2Plus mpl10 ]; 155 pkgConfigModules = [ 156 "cairo-ps" 157 "cairo-svg" 158 ] ++ lib.optional gobjectSupport "cairo-gobject" 159 ++ lib.optional pdfSupport "cairo-pdf"; 160 platforms = platforms.all; 161 }; 162})