-
Notifications
You must be signed in to change notification settings - Fork 9
/
flake.nix
194 lines (188 loc) · 8.77 KB
/
flake.nix
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
{
description = "All Python versions packages in Nix.";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
flake-compat.url = "github:edolstra/flake-compat";
flake-compat.flake = false;
};
nixConfig = {
substituters = "https://cache.nixos.org 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: lower: upper:
lib.versionOlder version lower && lib.versionAtLeast 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;
sourceVersion = {
major = builtins.elemAt versionList 0;
minor = builtins.elemAt versionList 1;
patch = builtins.elemAt versionList 2;
suffix = "";
};
infix = if sourceVersion.major == "2" then "2.7/" else "";
overrideLDConfigPatch = path: pkg: pkg.override {
noldconfigPatch = path;
};
replacePatch = name: patch: pkg: pkg.overrideAttrs (old: {
patches = (lib.filter (elem: if builtins.isNull elem then true else !lib.hasSuffix name elem) old.patches) ++ [ patch ];
});
filterOutPatch = name: pkg: replacePatch name null pkg;
overrides = [
# py2
{ condition = version: versionInBetween version "2.7.3" "2.6";
# patch not available
override = pkg: filterOutPatch "deterministic-build.patch" (filterOutPatch "no-win64-workaround.patch" pkg);
}
{ 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: filterOutPatch "find_library-gcc10.patch" (filterOutPatch "profile-task.patch" pkg);
}
# 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;
}
# py3
{ 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 null;
}
{ 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 = pkg: pkg.overrideAttrs (old: {
patches = old.patches ++ [(pkgs.fetchpatch {
url = "https://github.com/python/cpython/commit/8ea6353.patch";
sha256 = "xXRDwtMMhb66J4Lis0rtTNxARgPqLAqR2y3YtkJOt2g=";
})];
});
}
{ condition = version: versionInBetween version "3.4" "3.0";
override = pkg: (pkg.override {
# no existing patch available
noldconfigPatch = null;
# otherwise it segfaults
stdenv =
if pkgs.stdenv.isLinux
then pkgs.overrideCC pkgs.stdenv pkgs.gcc8
else pkgs.stdenv;
});
}
# fill in the missing pc file
{ condition = version: versionInBetween version "3.5.2" "3.0" && pkgs.stdenv.isLinux;
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;
});
}
];
callPackage = pkgs.newScope {
inherit python;
pkgsBuildHost = pkgs.pkgsBuildHost // {
"python${sourceVersion.major}${sourceVersion.minor}" = python;
};
};
python = (self.lib.applyOverrides overrides (callPackage "${pkgs.path}/pkgs/development/interpreters/python/cpython/${infix}default.nix" ({
inherit sourceVersion;
inherit (pkgs.darwin) configd;
hash = null;
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";
}))).overrideAttrs (old: {
src = pkgs.fetchurl {
inherit url;
sha256 = hash;
};
meta = old.meta // {
knownVulnerabilities = [];
};
});
in python;
lib.versions = builtins.fromJSON (builtins.readFile ./versions.json);
checks = 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
);
packages = self.checks;
};
}