-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathflake.nix
More file actions
411 lines (398 loc) · 15.1 KB
/
flake.nix
File metadata and controls
411 lines (398 loc) · 15.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
{
description = "All Python versions packages in Nix.";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
flake-compat.url = "github:edolstra/flake-compat";
flake-compat.flake = false;
};
nixConfig = {
extra-substituters = "https://nixpkgs-python.cachix.org";
extra-trusted-public-keys = "nixpkgs-python.cachix.org-1:hxjI7pFxTyuTHn2NkvWCrAUcNZLNS3ZAvfYNuYifcEU=";
};
outputs =
{ self, nixpkgs, ... }:
let
systems = [
"x86_64-linux"
"i686-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
];
forAllSystems =
f:
builtins.listToAttrs (
map (name: {
inherit name;
value = f name;
}) systems
);
lib = nixpkgs.lib;
versionInBetween =
version: upper: lower:
lib.versionAtLeast version lower && lib.versionOlder version upper;
in
{
lib.applyOverrides =
overrides: pkg:
let
matching = builtins.filter ({ condition, ... }: condition pkg.version) overrides;
apply = pkg: { override, ... }: override pkg;
in
lib.foldl apply pkg matching;
lib.mkPython =
{
pkgs,
version,
hash,
url,
packages,
}:
let
versionList = builtins.splitVersion version;
versionSuffixList = builtins.concatLists [
[ "" ]
(lib.drop 3 versionList)
];
sourceVersion = {
major = builtins.elemAt versionList 0;
minor = builtins.elemAt versionList 1;
patch = builtins.elemAt versionList 2;
suffix = builtins.concatStringsSep "." versionSuffixList;
};
infix = if sourceVersion.major == "2" then "2.7/" else "";
# Patch helpers
overrideLDConfigPatch =
path: pkg:
pkg.override {
noldconfigPatch = path;
};
# Override the patches of a derivation by applying a function f: oldPatches -> newPatches
applyPatches =
f: pkg:
pkg.overrideAttrs (old: {
patches = f old.patches;
});
# Replace a patch by name in a derivation.
replacePatch =
name: patch: pkg:
lib.pipe pkg [
(filterOutPatch name)
(appendPatches [ patch ])
];
# Remove a patch by name from a derivation.
filterOutPatch =
name:
applyPatches (lib.filter (elem: if builtins.isNull elem then true else !lib.hasSuffix name elem));
# Append patches to a derivation.
appendPatches = patches: applyPatches (oldPatches: oldPatches ++ patches);
overrides = [
# py2
{
condition = version: versionInBetween version "2.7.3" "2.6";
# patch not available
override =
pkg:
lib.pipe pkg [
(filterOutPatch "deterministic-build.patch")
(filterOutPatch "no-win64-workaround.patch")
];
}
{
condition = version: versionInBetween version "2.7.4" "2.6";
# patch not available
override = filterOutPatch "atomic_pyc.patch";
}
{
condition = version: versionInBetween version "3.7" "3.3";
# patch not available
override = filterOutPatch "loongarch-support.patch";
}
{
condition = version: versionInBetween version "2.7.13" "2.6";
override =
pkg:
lib.pipe pkg [
(filterOutPatch "find_library-gcc10.patch")
(filterOutPatch "profile-task.patch")
(appendPatches [ ./patches/2.7-get-entropy-macos.patch ])
];
}
# patch not available before 2.7.11
{
condition = version: versionInBetween version "2.7.11" "2.6";
override = filterOutPatch "no-ldconfig.patch";
}
{
condition = version: versionInBetween version "2.7.12" "2.7.11";
override = replacePatch "no-ldconfig.patch" ./patches/2.7.10-no-ldconfig.patch;
}
{
condition = version: versionInBetween version "2.7.13" "2.7.12";
override = replacePatch "no-ldconfig.patch" ./patches/2.7.11-no-ldconfig.patch;
}
{
condition = version: versionInBetween version "2.7.17" "2.7.6";
override = replacePatch "python-2.7-distutils-C++.patch" ./patches/2.7.17-distutils-C++.patch;
}
# this patch reverts an ActiveState change that was introduced in 2.7.18.8
{
condition = version: versionInBetween version "2.7.18.8" "2.7";
override = filterOutPatch "20ea5b46aaf1e7bdf9d6905ba8bece2cc73b05b0.patch";
}
# py3
{
condition = version: versionInBetween version "3.5.2" "3.5";
override = appendPatches [
./patches/3.5-pythreadstate-uncheckedget.patch
./patches/3.5-incompatible-types-atomic-pointers.patch
];
}
{
condition = version: versionInBetween version "3.5.3" "3.5";
override = appendPatches (
(lib.optionals (version == "3.5.0") [ ./patches/3.5.0-os-random-prepatch.patch ])
++ [ ./patches/3.5-get-entropy-macos.patch ]
);
}
{
condition = version: versionInBetween version "3.8.7" "3.8";
override = overrideLDConfigPatch ./patches/3.8.6-no-ldconfig.patch;
}
{
condition = version: versionInBetween version "3.7.10" "3.7";
override = overrideLDConfigPatch ./patches/3.7.9-no-ldconfig.patch;
}
{
condition = version: versionInBetween version "3.7.3" "3.7";
override = filterOutPatch "fix-finding-headers-when-cross-compiling.patch";
}
{
condition = version: versionInBetween version "3.7.3" "3.7.1";
override = replacePatch "python-3.x-distutils-C++.patch" (
pkgs.fetchpatch {
url = "https://bugs.python.org/file48016/python-3.x-distutils-C++.patch";
sha256 = "1h18lnpx539h5lfxyk379dxwr8m2raigcjixkf133l4xy3f4bzi2";
}
);
}
{
condition = version: versionInBetween version "3.7.4" "3.7.3";
override = replacePatch "python-3.x-distutils-C++.patch" ./patches/python-3.7.3-distutils-C++.patch;
}
{
condition =
version: versionInBetween version "3.7.2" "3.7" || versionInBetween version "3.6.8" "3.6.6";
override = replacePatch "python-3.x-distutils-C++.patch" (
pkgs.fetchpatch {
url = "https://bugs.python.org/file47669/python-3.8-distutils-C++.patch";
sha256 = "0s801d7ww9yrk6ys053jvdhl0wicbznx08idy36f1nrrxsghb3ii";
}
);
}
{
condition = version: versionInBetween version "3.5.3" "3.5";
# no existing patch available
override = overrideLDConfigPatch ./patches/no-op.patch;
}
{
condition = version: versionInBetween version "3.6.6" "3.4";
override = replacePatch "python-3.x-distutils-C++.patch" (
pkgs.fetchpatch {
url = "https://bugs.python.org/file47046/python-3.x-distutils-C++.patch";
sha256 = "0dgdn9k2kmw4wh90vdnjcrnn97ylxgx7mbn9l87fwz6j501jqvk8";
extraPrefix = "";
}
);
}
# no C++ patch for 3.3
{
condition = version: versionInBetween version "3.4" "3.0";
override = filterOutPatch "python-3.x-distutils-C++.patch";
}
# fix darwin compilation
{
condition =
version: versionInBetween version "3.8.4" "3.8" || versionInBetween version "3.7.8" "3.0";
override = appendPatches [
(pkgs.fetchpatch {
url = "https://github.com/python/cpython/commit/8ea6353.patch";
sha256 = "xXRDwtMMhb66J4Lis0rtTNxARgPqLAqR2y3YtkJOt2g=";
})
];
}
# Fix ensurepip for 3.6: https://bugs.python.org/issue45700
{
condition = version: versionInBetween version "3.6.15" "3.6";
override = appendPatches [
(pkgs.fetchpatch {
url = "https://github.com/python/cpython/commit/8766cb74e186d3820db0a855.patch";
sha256 = "IzAp3M6hpSNcbVRttzvXNDyAVK7vLesKZDEDkdYbuww=";
})
(pkgs.fetchpatch {
url = "https://github.com/python/cpython/commit/f0be4bbb9b3cee876249c23f.patch";
sha256 = "FUF7ZkkatS4ON4++pR9XJQFQLW1kKSVzSs8NAS19bDY=";
})
];
}
{
condition = version: versionInBetween version "3.4" "3.0";
override =
pkg:
(pkg.override {
# no existing patch available
noldconfigPatch = ./patches/no-op.patch;
# otherwise it segfaults
stdenv =
if pkgs.stdenv.isLinux then
pkgs.overrideCC pkgs.stdenv pkgs.gcc9 # gcc8 no longer available
else
pkgs.stdenv;
});
}
# compatibility with substitutions done by the nixpkgs derivation
{
condition = version: versionInBetween version "3.7" "3.0";
override =
pkg:
pkg.overrideAttrs (old: {
prePatch =
''
substituteInPlace Lib/subprocess.py --replace-fail '"/bin/sh"' "'/bin/sh'"
''
+ old.prePatch;
});
}
# fill in the missing pc file
{
condition = version: versionInBetween version "3.5.2" "3.0";
override =
pkg:
pkg.overrideAttrs (old: {
postInstall =
''
ln -s "$out/lib/pkgconfig/python-${pkg.passthru.sourceVersion.major}.${pkg.passthru.sourceVersion.minor}.pc" "$out/lib/pkgconfig/python3.pc"
''
+ old.postInstall;
});
}
{
condition = version: lib.versionOlder version "3.12";
override = filterOutPatch "CVE-2025-0938.patch";
}
{
condition = version: versionInBetween version "3.12" "3.11";
override = filterOutPatch "f4b31edf2d9d72878dab1f66a36913b5bcc848ec.patch";
}
];
callPackage = pkgs.newScope {
inherit python;
pkgsBuildHost = pkgs.pkgsBuildHost // {
"python${sourceVersion.major}${sourceVersion.minor}" = python;
};
};
pythonFun = import "${toString pkgs.path}/pkgs/development/interpreters/python/cpython/${infix}default.nix";
python =
(self.lib.applyOverrides overrides (
callPackage pythonFun (
{
inherit sourceVersion;
hash = "sha256-${hash}";
self = packages.${version};
passthruFun = callPackage "${pkgs.path}/pkgs/development/interpreters/python/passthrufun.nix" { };
}
// lib.optionalAttrs (sourceVersion.major == "3") {
noldconfigPatch = ./patches + "/${sourceVersion.major}.${sourceVersion.minor}-no-ldconfig.patch";
}
// lib.optionalAttrs (lib.functionArgs pythonFun ? configd) {
# Nixpkgs had a Darwin SDK refactor in 24.11 which removed configd from the Python derivation
# Only inject configd for older Nixpkgs where it's required.
inherit (pkgs.darwin) configd;
}
)
)).overrideAttrs
(old: {
src = pkgs.fetchurl {
inherit url;
sha256 = hash;
};
meta = old.meta // {
knownVulnerabilities = [ ];
};
});
in
python;
lib.versions = builtins.fromJSON (builtins.readFile ./versions.json);
packages = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
getRelease =
version: source:
self.lib.mkPython {
inherit pkgs version packages;
inherit (source) hash url;
};
getLatest = version: latest: getRelease latest self.lib.versions.releases.${latest};
packages =
pkgs.lib.mapAttrs getRelease self.lib.versions.releases
// pkgs.lib.mapAttrs getLatest self.lib.versions.latest;
in
packages
);
patchChecks = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
patchedPackages = pkgs.lib.mapAttrs (
name: pkg:
pkg.overrideAttrs (_: {
phases = [
"unpackPhase"
"patchPhase"
"installPhase"
];
installPhase = "mkdir -p $out";
separateDebugInfo = false;
dontStrip = true;
})
) self.packages.${system};
in
patchedPackages
// {
all = pkgs.linkFarm "all-patch-checks" (
lib.mapAttrsToList (name: drv: {
inherit name;
path = drv;
}) patchedPackages
);
}
);
checks = forAllSystems (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
pkgs.lib.concatMapAttrs (
version: python:
{
${version} = python;
}
// lib.optionalAttrs (versionInBetween version "3" "2.7.18") {
${version + "-ssl"} = pkgs.runCommand "${version}-test-ssl" { } ''
set -x
mkdir $out
${python}/bin/python -c 'import ssl; print(ssl.OPENSSL_VERSION)' | tee $out/openssl-version
'';
}
// lib.optionalAttrs (versionInBetween version "3.12" "3.6") {
${version + "-ensurepip"} = pkgs.runCommand "${version}-test-ensurepip" { } ''
set -x
mkdir $out
${python}/bin/python -m ensurepip --help | tee $out/ensurepip-help
'';
}
) self.packages.${system}
);
};
}