nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchurl,
5 autoPatchelfHook,
6 python-setup-hook,
7 self,
8 # Dependencies
9 bzip2,
10 expat,
11 gdbm,
12 ncurses6,
13 sqlite,
14 tcl-8_5,
15 tk-8_5,
16 tcl-8_6,
17 tk-8_6,
18 zlib,
19 # For the Python package set
20 packageOverrides ? (self: super: { }),
21 sourceVersion,
22 pythonVersion,
23 hash,
24 passthruFun,
25}:
26
27# This version of PyPy is primarily added to speed-up translation of
28# our PyPy source build when developing that expression.
29
30let
31 isPy3k = majorVersion == "3";
32 passthru = passthruFun {
33 inherit
34 self
35 sourceVersion
36 pythonVersion
37 packageOverrides
38 ;
39 implementation = "pypy";
40 libPrefix = "pypy${pythonVersion}";
41 executable = "pypy${lib.optionalString isPy3k "3"}";
42 sitePackages = "site-packages";
43 hasDistutilsCxxPatch = false;
44
45 # Not possible to cross-compile with.
46 pythonOnBuildForBuild = throw "${pname} does not support cross compilation";
47 pythonOnBuildForHost = self;
48 pythonOnBuildForTarget = throw "${pname} does not support cross compilation";
49 pythonOnHostForHost = throw "${pname} does not support cross compilation";
50 pythonOnTargetForTarget = throw "${pname} does not support cross compilation";
51
52 pythonABITags = [
53 "none"
54 "pypy${lib.concatStrings (lib.take 2 (lib.splitString "." pythonVersion))}_pp${sourceVersion.major}${sourceVersion.minor}"
55 ];
56 };
57 pname = "${passthru.executable}_prebuilt";
58 version = with sourceVersion; "${major}.${minor}.${patch}";
59
60 majorVersion = lib.versions.major pythonVersion;
61
62 downloadUrls = {
63 aarch64-linux = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-aarch64.tar.bz2";
64 x86_64-linux = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-linux64.tar.bz2";
65 aarch64-darwin = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-macos_arm64.tar.bz2";
66 x86_64-darwin = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-macos_x86_64.tar.bz2";
67 };
68
69in
70with passthru;
71stdenv.mkDerivation {
72 inherit pname version;
73
74 src = fetchurl {
75 url = downloadUrls.${stdenv.system} or (throw "Unsupported system: ${stdenv.system}");
76 inherit hash;
77 };
78
79 buildInputs = [
80 bzip2
81 expat
82 gdbm
83 ncurses6
84 sqlite
85 zlib
86 stdenv.cc.cc.libgcc or null
87 ]
88 ++ lib.optionals stdenv.hostPlatform.isLinux [
89 tcl-8_5
90 tk-8_5
91 ]
92 ++ lib.optionals stdenv.hostPlatform.isDarwin [
93 tcl-8_6
94 tk-8_6
95 ];
96
97 nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ];
98
99 installPhase = ''
100 runHook preInstall
101
102 mkdir -p $out/lib
103 echo "Moving files to $out"
104 mv -t $out bin include lib-python lib_pypy site-packages
105 mv $out/bin/libpypy*-c${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/
106 ${lib.optionalString stdenv.hostPlatform.isLinux ''
107 rm $out/bin/*.debug
108 ''}
109
110 echo "Removing bytecode"
111 find . -name "__pycache__" -type d -depth -delete
112
113 # Include a sitecustomize.py file
114 cp ${../sitecustomize.py} $out/${sitePackages}/sitecustomize.py
115
116 runHook postInstall
117 '';
118
119 preFixup =
120 lib.optionalString (stdenv.hostPlatform.isLinux) ''
121 find $out/{lib,lib_pypy*} -name "*.so" \
122 -exec patchelf \
123 --replace-needed libtinfow.so.6 libncursesw.so.6 \
124 --replace-needed libgdbm.so.4 libgdbm_compat.so.4 {} \;
125 ''
126 + lib.optionalString (stdenv.hostPlatform.isDarwin) ''
127 install_name_tool \
128 -change \
129 @rpath/lib${executable}-c.dylib \
130 $out/lib/lib${executable}-c.dylib \
131 $out/bin/${executable}
132 install_name_tool \
133 -change \
134 /opt/homebrew${lib.optionalString stdenv.hostPlatform.isx86_64 "_x86_64"}/opt/tcl-tk/lib/libtcl8.6.dylib \
135 ${tcl-8_6}/lib/libtcl8.6.dylib \
136 $out/lib_pypy/_tkinter/*.so
137 install_name_tool \
138 -change \
139 /opt/homebrew${lib.optionalString stdenv.hostPlatform.isx86_64 "_x86_64"}/opt/tcl-tk/lib/libtk8.6.dylib \
140 ${tk-8_6}/lib/libtk8.6.dylib \
141 $out/lib_pypy/_tkinter/*.so
142 '';
143
144 doInstallCheck = true;
145
146 # Check whether importing of (extension) modules functions
147 installCheckPhase =
148 let
149 modules = [
150 "ssl"
151 "sys"
152 "curses"
153 ]
154 ++ lib.optionals (!isPy3k) [
155 "Tkinter"
156 ]
157 ++ lib.optionals isPy3k [
158 "tkinter"
159 ];
160 imports = lib.concatMapStringsSep "; " (x: "import ${x}") modules;
161 in
162 ''
163 echo "Testing whether we can import modules"
164 $out/bin/${executable} -c '${imports}'
165 '';
166
167 setupHook = python-setup-hook sitePackages;
168
169 donPatchElf = true;
170 dontStrip = true;
171
172 inherit passthru;
173
174 meta = {
175 homepage = "http://pypy.org/";
176 description = "Fast, compliant alternative implementation of the Python language (${pythonVersion})";
177 license = lib.licenses.mit;
178 platforms = lib.attrNames downloadUrls;
179 };
180
181}