1{ stdenv, substituteAll, fetchurl
2, zlib ? null, zlibSupport ? true, bzip2, pkgconfig, libffi
3, sqlite, openssl, ncurses, python, expat, tcl, tk, tix, xlibsWrapper, libX11
4, makeWrapper, callPackage, self, gdbm, db
5, python-setup-hook
6# For the Python package set
7, pkgs, packageOverrides ? (self: super: {})
8}:
9
10assert zlibSupport -> zlib != null;
11
12let
13 majorVersion = "5.10";
14 minorVersion = "0";
15 minorVersionSuffix = "";
16 pythonVersion = "2.7";
17 version = "${majorVersion}.${minorVersion}${minorVersionSuffix}";
18 libPrefix = "pypy${majorVersion}";
19 sitePackages = "site-packages";
20
21 pythonForPypy = python.withPackages (ppkgs: [ ppkgs.pycparser ]);
22
23in stdenv.mkDerivation rec {
24 name = "pypy-${version}";
25 inherit majorVersion version pythonVersion;
26
27 src = fetchurl {
28 url = "https://bitbucket.org/pypy/pypy/get/release-pypy${pythonVersion}-v${version}.tar.bz2";
29 sha256 = "10j1s6r6iv80nvpi6gv8w05v505h2ndj9xx31yz7d50ab04dfg23";
30 };
31
32 nativeBuildInputs = [ pkgconfig makeWrapper ];
33 buildInputs = [
34 bzip2 openssl pythonForPypy libffi ncurses expat sqlite tk tcl xlibsWrapper libX11 gdbm db
35 ] ++ stdenv.lib.optional (stdenv ? cc && stdenv.cc.libc != null) stdenv.cc.libc
36 ++ stdenv.lib.optional zlibSupport zlib;
37
38 hardeningDisable = stdenv.lib.optional stdenv.isi686 "pic";
39
40 C_INCLUDE_PATH = stdenv.lib.makeSearchPathOutput "dev" "include" buildInputs;
41 LIBRARY_PATH = stdenv.lib.makeLibraryPath buildInputs;
42 LD_LIBRARY_PATH = stdenv.lib.makeLibraryPath (stdenv.lib.filter (x : x.outPath != stdenv.cc.libc.outPath or "") buildInputs);
43
44 patches = [
45 (substituteAll {
46 src = ./tk_tcl_paths.patch;
47 inherit tk tcl;
48 tk_dev = tk.dev;
49 tcl_dev = tcl;
50 tk_libprefix = tk.libPrefix;
51 tcl_libprefix = tcl.libPrefix;
52 })
53 ];
54
55 postPatch = ''
56 substituteInPlace "lib-python/2.7/lib-tk/Tix.py" --replace "os.environ.get('TIX_LIBRARY')" "os.environ.get('TIX_LIBRARY') or '${tix}/lib'"
57
58 # hint pypy to find nix ncurses
59 substituteInPlace pypy/module/_minimal_curses/fficurses.py \
60 --replace "/usr/include/ncurses/curses.h" "${ncurses.dev}/include/curses.h" \
61 --replace "ncurses/curses.h" "${ncurses.dev}/include/curses.h" \
62 --replace "ncurses/term.h" "${ncurses.dev}/include/term.h" \
63 --replace "libraries=['curses']" "libraries=['ncurses']"
64
65 sed -i "s@libraries=\['sqlite3'\]\$@libraries=['sqlite3'], include_dirs=['${sqlite.dev}/include'], library_dirs=['${sqlite.out}/lib']@" lib_pypy/_sqlite3_build.py
66 '';
67
68 buildPhase = ''
69 ${pythonForPypy.interpreter} rpython/bin/rpython \
70 --make-jobs="$NIX_BUILD_CORES" \
71 -Ojit \
72 --batch pypy/goal/targetpypystandalone.py \
73 --withmod-_minimal_curses \
74 --withmod-unicodedata \
75 --withmod-thread \
76 --withmod-bz2 \
77 --withmod-_multiprocessing
78 '';
79
80 setupHook = python-setup-hook sitePackages;
81
82 doCheck = true;
83 checkPhase = ''
84 export TERMINFO="${ncurses.out}/share/terminfo/";
85 export TERM="xterm";
86 export HOME="$TMPDIR";
87 # disable shutils because it assumes gid 0 exists
88 # disable socket because it has two actual network tests that fail
89 # disable test_urllib2net, test_urllib2_localnet, and test_urllibnet because they require networking (example.com)
90 # disable test_ssl because no shared cipher' not found in '[Errno 1] error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
91 # disable test_zipfile64 because it causes ENOSPACE
92 ./pypy-c ./pypy/test_all.py --pypy=./pypy-c -k 'not ( test_ssl or test_urllib2net or test_urllibnet or test_urllib2_localnet or test_socket or test_shutil or test_zipfile64 )' lib-python
93 '';
94
95 installPhase = ''
96 mkdir -p $out/{bin,include,lib,pypy-c}
97
98 cp -R {include,lib_pypy,lib-python,pypy-c} $out/pypy-c
99 cp libpypy-c.so $out/lib/
100 ln -s $out/pypy-c/pypy-c $out/bin/pypy
101 chmod +x $out/bin/pypy
102
103 # other packages expect to find stuff according to libPrefix
104 ln -s $out/pypy-c/include $out/include/${libPrefix}
105 ln -s $out/pypy-c/lib-python/${pythonVersion} $out/lib/${libPrefix}
106
107 # We must wrap the original, not the symlink.
108 # PyPy uses argv[0] to find its standard library, and while it knows
109 # how to follow symlinks, it doesn't know about wrappers. So, it
110 # will think the wrapper is the original. As long as the wrapper has
111 # the same path as the original, this is OK.
112 wrapProgram "$out/pypy-c/pypy-c" \
113 --set LD_LIBRARY_PATH "${LD_LIBRARY_PATH}:$out/lib" \
114 --set LIBRARY_PATH "${LIBRARY_PATH}:$out/lib"
115
116 # verify cffi modules
117 $out/bin/pypy -c "import Tkinter;import sqlite3;import curses"
118
119 # Python on Nix is not manylinux1 compatible. https://github.com/NixOS/nixpkgs/issues/18484
120 echo "manylinux1_compatible=False" >> $out/lib/${libPrefix}/_manylinux.py
121 '';
122
123 passthru = let
124 pythonPackages = callPackage ../../../../../top-level/python-packages.nix {python=self; overrides=packageOverrides;};
125 in rec {
126 inherit zlibSupport libPrefix sitePackages;
127 executable = "pypy";
128 isPypy = true;
129 buildEnv = callPackage ../../wrapper.nix { python = self; inherit (pythonPackages) requiredPythonModules; };
130 interpreter = "${self}/bin/${executable}";
131 withPackages = import ../../with-packages.nix { inherit buildEnv pythonPackages;};
132 pkgs = pythonPackages;
133 };
134
135 enableParallelBuilding = true; # almost no parallelization without STM
136
137 meta = with stdenv.lib; {
138 homepage = http://pypy.org/;
139 description = "Fast, compliant alternative implementation of the Python language (2.7.13)";
140 license = licenses.mit;
141 platforms = [ "i686-linux" "x86_64-linux" ];
142 maintainers = with maintainers; [ ];
143 };
144}