1{ __splicedPackages
2, callPackage
3, config
4, darwin
5, db
6, lib
7, libffiBoot
8, makeScopeWithSplicing
9, pythonPackagesExtensions
10, stdenv
11}:
12
13(let
14
15 # Common passthru for all Python interpreters.
16 passthruFun =
17 { implementation
18 , libPrefix
19 , executable
20 , sourceVersion
21 , pythonVersion
22 , packageOverrides
23 , sitePackages
24 , hasDistutilsCxxPatch
25 , pythonOnBuildForBuild
26 , pythonOnBuildForHost
27 , pythonOnBuildForTarget
28 , pythonOnHostForHost
29 , pythonOnTargetForTarget
30 , pythonAttr ? null
31 , self # is pythonOnHostForTarget
32 }: let
33 pythonPackages = let
34 ensurePythonModules = items: let
35 exceptions = [
36 stdenv
37 ];
38 providesSetupHook = lib.attrByPath [ "provides" "setupHook"] false;
39 valid = value: pythonPackages.hasPythonModule value || providesSetupHook value || lib.elem value exceptions;
40 func = name: value:
41 if lib.isDerivation value then
42 lib.extendDerivation (valid value || throw "${name} should use `buildPythonPackage` or `toPythonModule` if it is to be part of the Python packages set.") {} value
43 else
44 value;
45 in lib.mapAttrs func items;
46 in ensurePythonModules (callPackage
47 # Function that when called
48 # - imports python-packages.nix
49 # - adds spliced package sets to the package set
50 # - applies overrides from `packageOverrides` and `pythonPackagesOverlays`.
51 ({ pkgs, stdenv, python, overrides }: let
52 pythonPackagesFun = import ./python-packages-base.nix {
53 inherit stdenv pkgs lib;
54 python = self;
55 };
56 otherSplices = {
57 selfBuildBuild = pythonOnBuildForBuild.pkgs;
58 selfBuildHost = pythonOnBuildForHost.pkgs;
59 selfBuildTarget = pythonOnBuildForTarget.pkgs;
60 selfHostHost = pythonOnHostForHost.pkgs;
61 selfTargetTarget = pythonOnTargetForTarget.pkgs or {}; # There is no Python TargetTarget.
62 };
63 hooks = import ./hooks/default.nix;
64 keep = lib.extends hooks pythonPackagesFun;
65 extra = _: {};
66 optionalExtensions = cond: as: lib.optionals cond as;
67 pythonExtension = import ../../../top-level/python-packages.nix;
68 python2Extension = import ../../../top-level/python2-packages.nix;
69 extensions = lib.composeManyExtensions ([
70 pythonExtension
71 ] ++ (optionalExtensions (!self.isPy3k) [
72 python2Extension
73 ]) ++ pythonPackagesExtensions ++ [
74 overrides
75 ]);
76 aliases = self: super: lib.optionalAttrs config.allowAliases (import ../../../top-level/python-aliases.nix lib self super);
77 in makeScopeWithSplicing
78 otherSplices
79 keep
80 extra
81 (lib.extends (lib.composeExtensions aliases extensions) keep))
82 {
83 overrides = packageOverrides;
84 python = self;
85 });
86 in rec {
87 isPy27 = pythonVersion == "2.7";
88 isPy37 = pythonVersion == "3.7";
89 isPy38 = pythonVersion == "3.8";
90 isPy39 = pythonVersion == "3.9";
91 isPy310 = pythonVersion == "3.10";
92 isPy311 = pythonVersion == "3.11";
93 isPy312 = pythonVersion == "3.12";
94 isPy2 = lib.strings.substring 0 1 pythonVersion == "2";
95 isPy3 = lib.strings.substring 0 1 pythonVersion == "3";
96 isPy3k = isPy3;
97 isPyPy = lib.hasInfix "pypy" interpreter;
98
99 buildEnv = callPackage ./wrapper.nix { python = self; inherit (pythonPackages) requiredPythonModules; };
100 withPackages = import ./with-packages.nix { inherit buildEnv pythonPackages;};
101 pkgs = pythonPackages;
102 interpreter = "${self}/bin/${executable}";
103 inherit executable implementation libPrefix pythonVersion sitePackages;
104 inherit sourceVersion;
105 pythonAtLeast = lib.versionAtLeast pythonVersion;
106 pythonOlder = lib.versionOlder pythonVersion;
107 inherit hasDistutilsCxxPatch;
108 # TODO: rename to pythonOnBuild
109 # Not done immediately because its likely used outside Nixpkgs.
110 pythonForBuild = pythonOnBuildForHost.override { inherit packageOverrides; self = pythonForBuild; };
111
112 tests = callPackage ./tests.nix {
113 python = self;
114 };
115
116 inherit pythonAttr;
117 };
118
119 sources = {
120 python310 = {
121 sourceVersion = {
122 major = "3";
123 minor = "10";
124 patch = "11";
125 suffix = "";
126 };
127 hash = "sha256-PDvDBIMDchyQSgPrgya2Mekh8RzDvimIRWpC8RXa8Ew=";
128 };
129
130 python311 = {
131 sourceVersion = {
132 major = "3";
133 minor = "11";
134 patch = "3";
135 suffix = "";
136 };
137 hash = "sha256-il25nJYafs8nx1lWGJyWAslodR8R2+riuQDb/xwIW14=";
138 };
139 };
140
141in {
142
143 python27 = callPackage ./cpython/2.7 {
144 self = __splicedPackages.python27;
145 sourceVersion = {
146 major = "2";
147 minor = "7";
148 patch = "18";
149 suffix = ".6"; # ActiveState's Python 2 extended support
150 };
151 hash = "sha256-+I0QOBkuTHMIQz71lgNn1X1vjPsjJMtFbgC0xcGTwWY=";
152 inherit (darwin) configd;
153 inherit passthruFun;
154 };
155
156 python38 = callPackage ./cpython {
157 self = __splicedPackages.python38;
158 sourceVersion = {
159 major = "3";
160 minor = "8";
161 patch = "16";
162 suffix = "";
163 };
164 hash = "sha256-2F27N3QTJHPYCB3LFY80oQzK16kLlsflDqS7YfXORWI=";
165 inherit (darwin) configd;
166 inherit passthruFun;
167 };
168
169 python39 = callPackage ./cpython {
170 self = __splicedPackages.python39;
171 sourceVersion = {
172 major = "3";
173 minor = "9";
174 patch = "16";
175 suffix = "";
176 };
177 hash = "sha256-It3cCZJG3SdgZlVh6K23OU6gzEOnJoTGSA+TgPd4ZDk=";
178 inherit (darwin) configd;
179 inherit passthruFun;
180 };
181
182 python310 = callPackage ./cpython ({
183 self = __splicedPackages.python310;
184 inherit (darwin) configd;
185 inherit passthruFun;
186 } // sources.python310);
187
188 python311 = callPackage ./cpython ({
189 self = __splicedPackages.python311;
190 inherit (darwin) configd;
191 inherit passthruFun;
192 } // sources.python311);
193
194 python312 = callPackage ./cpython {
195 self = __splicedPackages.python312;
196 sourceVersion = {
197 major = "3";
198 minor = "12";
199 patch = "0";
200 suffix = "b1";
201 };
202 hash = "sha256-i6dspkrNdFur37hGeCCWTfmIWO5qlXe/HZNEcle+WB4=";
203 inherit (darwin) configd;
204 inherit passthruFun;
205 };
206
207 # Minimal versions of Python (built without optional dependencies)
208 python3Minimal = (callPackage ./cpython ({
209 self = __splicedPackages.python3Minimal;
210 inherit passthruFun;
211 pythonAttr = "python3Minimal";
212 # strip down that python version as much as possible
213 openssl = null;
214 readline = null;
215 ncurses = null;
216 gdbm = null;
217 sqlite = null;
218 configd = null;
219 tzdata = null;
220 libffi = libffiBoot; # without test suite
221 stripConfig = true;
222 stripIdlelib = true;
223 stripTests = true;
224 stripTkinter = true;
225 rebuildBytecode = false;
226 stripBytecode = true;
227 includeSiteCustomize = false;
228 enableOptimizations = false;
229 enableLTO = false;
230 mimetypesSupport = false;
231 } // sources.python310)).overrideAttrs(old: {
232 # TODO(@Artturin): Add this to the main cpython expr
233 strictDeps = true;
234 pname = "python3-minimal";
235 });
236
237 pypy27 = callPackage ./pypy {
238 self = __splicedPackages.pypy27;
239 sourceVersion = {
240 major = "7";
241 minor = "3";
242 patch = "11";
243 };
244
245 hash = "sha256-ERevtmgx2k6m852NIIR4enRon9AineC+MB+e2bJVCTw=";
246 pythonVersion = "2.7";
247 db = db.override { dbmSupport = !stdenv.isDarwin; };
248 python = __splicedPackages.pythonInterpreters.pypy27_prebuilt;
249 inherit passthruFun;
250 inherit (darwin) libunwind;
251 inherit (darwin.apple_sdk.frameworks) Security;
252 };
253
254 pypy39 = callPackage ./pypy {
255 self = __splicedPackages.pypy39;
256 sourceVersion = {
257 major = "7";
258 minor = "3";
259 patch = "11";
260 };
261
262 hash = "sha256-sPMWb7Klqt/VzrnbXN1feSmg7MygK0omwNrgSS98qOo=";
263 pythonVersion = "3.9";
264 db = db.override { dbmSupport = !stdenv.isDarwin; };
265 python = __splicedPackages.pypy27;
266 inherit passthruFun;
267 inherit (darwin) libunwind;
268 inherit (darwin.apple_sdk.frameworks) Security;
269 };
270
271 pypy38 = __splicedPackages.pypy39.override {
272 self = __splicedPackages.pythonInterpreters.pypy38;
273 pythonVersion = "3.8";
274 hash = "sha256-TWdpv8pzc06GZv1wUDt86wam4lkRDmFzMbs4mcpOYFg=";
275 };
276
277 pypy37 = throw "pypy37 has been removed from nixpkgs since it is no longer supported upstream"; # Added 2023-01-04
278
279 pypy27_prebuilt = callPackage ./pypy/prebuilt_2_7.nix {
280 # Not included at top-level
281 self = __splicedPackages.pythonInterpreters.pypy27_prebuilt;
282 sourceVersion = {
283 major = "7";
284 minor = "3";
285 patch = "11";
286 };
287
288 hash = {
289 aarch64-linux = "sha256-6pJNod7+kyXvdg4oiwT5hGFOQFWA9TIetqXI9Tm9QVo=";
290 x86_64-linux = "sha256-uo7ZWKkFwHNaTP/yh1wlCJlU3AIOCH2YKw/6W52jFs0=";
291 aarch64-darwin = "sha256-zFaWq0+TzTSBweSZC13t17pgrAYC+hiQ02iImmxb93E=";
292 x86_64-darwin = "sha256-Vt7unCJkD1aGw1udZP2xzjq9BEWD5AePCxccov0qGY4=";
293 }.${stdenv.system};
294 pythonVersion = "2.7";
295 inherit passthruFun;
296 };
297
298 pypy39_prebuilt = callPackage ./pypy/prebuilt.nix {
299 # Not included at top-level
300 self = __splicedPackages.pythonInterpreters.pypy38_prebuilt;
301 sourceVersion = {
302 major = "7";
303 minor = "3";
304 patch = "11";
305 };
306 hash = {
307 aarch64-linux = "sha256-CRddxlLtiV2Y6a1j0haBK/PufjmNkAqb+espBrqDArk=";
308 x86_64-linux = "sha256-1QYXLKEQcSdBdddOnFgcMWZDLQF5sDZHDjuejSDq5YE=";
309 aarch64-darwin = "sha256-ka11APGjlTHb76CzRaPc/5J/+ZcWVOjS6e98WuMR9X4=";
310 x86_64-darwin = "sha256-0z9AsgcJmHJYWv1xhzV1ym6mOKJ9gjvGISOMWuglQu0=";
311 }.${stdenv.system};
312 pythonVersion = "3.9";
313 inherit passthruFun;
314 };
315
316 rustpython = darwin.apple_sdk_11_0.callPackage ./rustpython/default.nix {
317 inherit (darwin.apple_sdk_11_0.frameworks) SystemConfiguration;
318 };
319
320})