1{ lib 2, buildPythonPackage 3, fetchPypi 4, pbr 5, pip 6, pkgs 7, stevedore 8, virtualenv 9, virtualenv-clone 10, python 11}: 12 13buildPythonPackage rec { 14 pname = "virtualenvwrapper"; 15 version = "4.8.4"; 16 17 src = fetchPypi { 18 inherit pname version; 19 sha256 = "51a1a934e7ed0ff221bdd91bf9d3b604d875afbb3aa2367133503fee168f5bfa"; 20 }; 21 22 # pip depend on $HOME setting 23 preConfigure = "export HOME=$TMPDIR"; 24 25 buildInputs = [ pbr pip pkgs.which ]; 26 propagatedBuildInputs = [ stevedore virtualenv virtualenv-clone ]; 27 28 postPatch = '' 29 for file in "virtualenvwrapper.sh" "virtualenvwrapper_lazy.sh"; do 30 substituteInPlace "$file" --replace "which" "${pkgs.which}/bin/which" 31 32 # We can't set PYTHONPATH in a normal way (like exporting in a wrapper 33 # script) because the user has to evaluate the script and we don't want 34 # modify the global PYTHONPATH which would affect the user's 35 # environment. 36 # Furthermore it isn't possible to just use VIRTUALENVWRAPPER_PYTHON 37 # for this workaround, because this variable is well quoted inside the 38 # shell script. 39 # (the trailing " -" is required to only replace things like these one: 40 # "$VIRTUALENVWRAPPER_PYTHON" -c "import os,[...] and not in 41 # if-statements or anything like that. 42 # ...and yes, this "patch" is hacky :) 43 substituteInPlace "$file" --replace '"$VIRTUALENVWRAPPER_PYTHON" -' 'env PYTHONPATH="$VIRTUALENVWRAPPER_PYTHONPATH" "$VIRTUALENVWRAPPER_PYTHON" -' 44 done 45 ''; 46 47 postInstall = '' 48 # This might look like a dirty hack but we can't use the makeWrapper function because 49 # the wrapped file were then called via "exec". The virtualenvwrapper shell scripts 50 # aren't normal executables. Instead, the user has to evaluate them. 51 52 for file in "virtualenvwrapper.sh" "virtualenvwrapper_lazy.sh"; do 53 local wrapper="$out/bin/$file" 54 local wrapped="$out/bin/.$file-wrapped" 55 mv "$wrapper" "$wrapped" 56 57 # WARNING: Don't indent the lines below because that would break EOF 58 cat > "$wrapper" << EOF 59export PATH="${python}/bin:\$PATH" 60export VIRTUALENVWRAPPER_PYTHONPATH="$PYTHONPATH:$(toPythonPath $out)" 61source "$wrapped" 62EOF 63 64 chmod -x "$wrapped" 65 chmod +x "$wrapper" 66 done 67 ''; 68 69 meta = with lib; { 70 description = "Enhancements to virtualenv"; 71 homepage = "https://pypi.python.org/pypi/virtualenvwrapper"; 72 license = licenses.mit; 73 }; 74 75}