From c4c812567f9009083e5187a89a4822a9455ee3a4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= <mail@nh2.me>
Date: Wed, 29 Jul 2020 05:21:36 +0200
Subject: [PATCH] fontforge: Fix uninterpolated `CMAKE_INSTALL_PREFIX` in
 RPATH.

This was introduced in https://github.com/NixOS/nixpkgs/pull/89583
and fixed upstream with a master-only patch in
https://github.com/fontforge/fontforge/pull/4232.

Found via
https://github.com/nh2/static-haskell-nix/pull/98#issuecomment-665395399.
---
 pkgs/tools/misc/fontforge/default.nix | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/pkgs/tools/misc/fontforge/default.nix b/pkgs/tools/misc/fontforge/default.nix
index 82fd5c8210d..8da5c871652 100644
--- a/pkgs/tools/misc/fontforge/default.nix
+++ b/pkgs/tools/misc/fontforge/default.nix
@@ -1,4 +1,5 @@
 { stdenv, fetchurl, lib
+, fetchpatch
 , cmake, perl, uthash, pkgconfig, gettext
 , python, freetype, zlib, glib, libungif, libpng, libjpeg, libtiff, libxml2, cairo, pango
 , readline, woff2, zeromq, libuninameslist
@@ -21,6 +22,18 @@ stdenv.mkDerivation rec {
     sha256 = "0qf88wd6riycq56d24brybyc93ns74s0nyyavm43zp2kfcihn6fd";
   };
 
+  patches = [
+    # Unreleased fix for https://github.com/fontforge/fontforge/issues/4229
+    # which is required to fix an uninterposated `${CMAKE_INSTALL_PREFIX}/lib`, see
+    # see https://github.com/nh2/static-haskell-nix/pull/98#issuecomment-665395399
+    # TODO: Remove https://github.com/fontforge/fontforge/pull/4232 is in a release.
+    (fetchpatch {
+      name = "fontforge-cmake-set-rpath-to-the-configure-time-CMAKE_INSTALL_PREFIX";
+      url = "https://github.com/fontforge/fontforge/commit/297ee9b5d6db5970ca17ebe5305189e79a1520a1.patch";
+      sha256 = "14qfp8pwh0vzzib4hq2nc6xhn8lc1cal1sb0lqwb2q5dijqx5kqk";
+    })
+  ];
+
   # use $SOURCE_DATE_EPOCH instead of non-deterministic timestamps
   postPatch = ''
     find . -type f -name '*.c' -exec sed -r -i 's#\btime\(&(.+)\)#if (getenv("SOURCE_DATE_EPOCH")) \1=atol(getenv("SOURCE_DATE_EPOCH")); else &#g' {} \;