From 71827091742d065d24498f3f5736cf58c31dea4f Mon Sep 17 00:00:00 2001
From: Thomas Tuegel <ttuegel@mailbox.org>
Date: Wed, 10 May 2017 16:20:11 -0500
Subject: [PATCH] grantlee: search profile library paths for plugins

---
 .../grantlee/{5.x.nix => 5/default.nix}       |  8 +++++---
 .../grantlee/5/grantlee-nix-profiles.patch    | 19 +++++++++++++++++++
 pkgs/development/libraries/grantlee/5/series  |  1 +
 pkgs/top-level/all-packages.nix               |  2 +-
 4 files changed, 26 insertions(+), 4 deletions(-)
 rename pkgs/development/libraries/grantlee/{5.x.nix => 5/default.nix} (81%)
 create mode 100644 pkgs/development/libraries/grantlee/5/grantlee-nix-profiles.patch
 create mode 100644 pkgs/development/libraries/grantlee/5/series

diff --git a/pkgs/development/libraries/grantlee/5.x.nix b/pkgs/development/libraries/grantlee/5/default.nix
similarity index 81%
rename from pkgs/development/libraries/grantlee/5.x.nix
rename to pkgs/development/libraries/grantlee/5/default.nix
index fb6af9c895d..7025877c847 100644
--- a/pkgs/development/libraries/grantlee/5.x.nix
+++ b/pkgs/development/libraries/grantlee/5/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, qtbase, qtscript, cmake }:
+{ stdenv, lib, copyPathsToStore, fetchurl, qtbase, qtscript, cmake }:
 
 stdenv.mkDerivation rec {
   name = "grantlee-${version}";
@@ -10,10 +10,12 @@ stdenv.mkDerivation rec {
     name = "${name}.tar.gz";
   };
 
+  patches = copyPathsToStore (lib.readPathsFromFile ./. ./series);
+
   buildInputs = [ qtbase qtscript ];
   nativeBuildInputs = [ cmake ];
 
-  meta = {
+  meta = with stdenv.lib; {
     description = "Qt5 port of Django template system";
     longDescription = ''
       Grantlee is a plugin based String Template system written using the Qt
@@ -25,7 +27,7 @@ stdenv.mkDerivation rec {
       and the design of Django is reused in Grantlee.'';
 
     homepage = http://gitorious.org/grantlee;
-    maintainers = [ ];
+    maintainers = [ maintainers.ttuegel ];
     inherit (qtbase.meta) platforms;
   };
 }
diff --git a/pkgs/development/libraries/grantlee/5/grantlee-nix-profiles.patch b/pkgs/development/libraries/grantlee/5/grantlee-nix-profiles.patch
new file mode 100644
index 00000000000..f6c13dbd6d5
--- /dev/null
+++ b/pkgs/development/libraries/grantlee/5/grantlee-nix-profiles.patch
@@ -0,0 +1,19 @@
+Index: grantlee-5.1.0/templates/lib/engine.cpp
+===================================================================
+--- grantlee-5.1.0.orig/templates/lib/engine.cpp
++++ grantlee-5.1.0/templates/lib/engine.cpp
+@@ -48,6 +48,14 @@ Engine::Engine(QObject *parent)
+ 
+   d_ptr->m_pluginDirs = QCoreApplication::instance()->libraryPaths();
+   d_ptr->m_pluginDirs << QString::fromLocal8Bit(GRANTLEE_PLUGIN_PATH);
++
++  // Add library paths derived from NIX_PROFILES.
++  const QByteArrayList profiles = qgetenv("NIX_PROFILES").split(' ');
++  for (const QByteArray &profile: profiles) {
++    if (!profile.isEmpty()) {
++      d_ptr->m_pluginDirs << (QFile::decodeName(profile) + QStringLiteral("/lib"));
++    }
++  }
+ }
+ 
+ Engine::~Engine()
diff --git a/pkgs/development/libraries/grantlee/5/series b/pkgs/development/libraries/grantlee/5/series
new file mode 100644
index 00000000000..16f04d44562
--- /dev/null
+++ b/pkgs/development/libraries/grantlee/5/series
@@ -0,0 +1 @@
+grantlee-nix-profiles.patch
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index a53c411753a..811d5f1745c 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -9979,7 +9979,7 @@ with pkgs;
 
     qgpgme = callPackage ../development/libraries/gpgme { };
 
-    grantlee = callPackage ../development/libraries/grantlee/5.x.nix { };
+    grantlee = callPackage ../development/libraries/grantlee/5 { };
 
     inherit (callPackage ../development/libraries/kirigami { })
       kirigami_1