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