From 67820820a6f53884e58addcd0c8055cf8745fe94 Mon Sep 17 00:00:00 2001
From: Jascha Geerds <jg@ekby.de>
Date: Fri, 8 Aug 2014 17:30:35 +0200
Subject: [PATCH] Fix virtualenvwrapper shell scripts

---
 pkgs/top-level/python-packages.nix | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix
index 2bf34a0623b..d2fcaed4c43 100644
--- a/pkgs/top-level/python-packages.nix
+++ b/pkgs/top-level/python-packages.nix
@@ -8168,6 +8168,15 @@ rec {
     patchPhase = ''
       substituteInPlace "virtualenvwrapper.sh" --replace "which" "${pkgs.which}/bin/which"
       substituteInPlace "virtualenvwrapper_lazy.sh" --replace "which" "${pkgs.which}/bin/which"
+
+      # This might look like a dirty hack but we can't use the makeWrapper function because
+      # the wrapped file were then called via "exec". The virtualenvwrapper shell scripts
+      # aren't normal executables. Instead, the user has to evaluate them.
+      for file in "virtualenvwrapper.sh" "virtualenvwrapper_lazy.sh"; do
+        # Insert the required PATH & PYTHONPATH variables right on the top
+        sed -i "2iexport PATH=$PATH:\$PATH" "$file"
+        sed -i "3iexport PYTHONPATH=$PYTHONPATH:$(toPythonPath $out):\$PYTHONPATH" "$file"
+      done
     '';
 
     meta = {