-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverlay.nix
245 lines (223 loc) · 8.5 KB
/
overlay.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
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
final: prev:
let
lib = import ./lib { inherit (prev) lib; };
cudaConfig =
(evalModules {
modules = [
./modules
{
cudaCapabilities = final.config.cudaCapabilities or [ ];
cudaForwardCompat = final.config.cudaForwardCompat or true;
hostNixSystem = final.stdenv.hostPlatform.system;
}
] ++ final.cudaModules;
}).config;
inherit (builtins) throw;
inherit (lib.attrsets)
attrNames
dontRecurseIntoAttrs
mapAttrs'
mergeAttrsList
recurseIntoAttrs
;
inherit (lib.cuda.utils)
buildRedistPackages
dropDots
mkCudaPackagesScope
mkCudaVariant
mkRealArchitecture
versionAtMost
versionBoundedExclusive
versionBoundedInclusive
versionNewer
;
inherit (lib.filesystem) packagesFromDirectoryRecursive;
inherit (lib.fixedPoints) composeManyExtensions extends;
inherit (lib.lists) map;
inherit (lib.modules) evalModules;
inherit (lib.strings)
replaceStrings
versionAtLeast
versionOlder
;
inherit (lib.upstreamable.trivial) addNameToFetchFromGitLikeArgs;
inherit (lib.versions) major majorMinor;
inherit (cudaConfig) hostRedistArch;
fetchFromGitHubAutoName =
args: final.fetchFromGitHub (addNameToFetchFromGitLikeArgs final.fetchFromGitHub args);
fetchFromGitLabAutoName =
args: final.fetchFromGitLab (addNameToFetchFromGitLikeArgs final.fetchFromGitLab args);
packageSetBuilder =
cudaMajorMinorPatchVersion:
let
# Attribute set membership can depend on the CUDA version, so we declare these here and ensure they do not rely on
# the fixed point.
cudaMajorMinorVersion = majorMinor cudaMajorMinorPatchVersion;
cudaMajorVersion = major cudaMajorMinorPatchVersion;
cudaAtLeast = versionAtLeast cudaMajorMinorPatchVersion;
cudaAtMost = versionAtMost cudaMajorMinorPatchVersion;
cudaNewer = versionNewer cudaMajorMinorPatchVersion;
cudaOlder = versionOlder cudaMajorMinorPatchVersion;
cudaBoundedExclusive = min: max: versionBoundedExclusive min max cudaMajorMinorPatchVersion;
cudaBoundedInclusive = min: max: versionBoundedInclusive min max cudaMajorMinorPatchVersion;
# Packaging-specific utilities.
desiredCudaVariant = mkCudaVariant cudaMajorMinorPatchVersion;
cudaPackagesConfig = cudaConfig.cudaPackages.${cudaMajorMinorPatchVersion};
cudaPackagesFun =
finalCudaPackages:
mergeAttrsList (
[
# Core attributes which largely don't depend on packages
(recurseIntoAttrs {
pkgs = dontRecurseIntoAttrs final // {
__attrsFailEvaluation = true;
};
cudaPackages = dontRecurseIntoAttrs finalCudaPackages // {
__attrsFailEvaluation = true;
};
# Introspection
cudaPackagesConfig = dontRecurseIntoAttrs cudaPackagesConfig // {
__attrsFailEvaluation = true;
};
# CUDA versions
inherit cudaMajorMinorPatchVersion cudaMajorMinorVersion cudaMajorVersion;
# CUDA version comparison utilities
inherit
cudaAtLeast
cudaAtMost
cudaBoundedExclusive
cudaBoundedInclusive
cudaNewer
cudaOlder
;
# Utility function for automatically naming fetchFromGitHub derivations with `name`.
fetchFromGitHub = fetchFromGitHubAutoName;
fetchFromGitLab = fetchFromGitLabAutoName;
# Name prefix
cudaNamePrefix = "cuda${cudaMajorMinorVersion}";
# Aliases
# TODO(@connorbaker): Warnings disabled for now.
backendStdenv = final.stdenv;
cudaVersion = cudaMajorMinorVersion;
cudaFlags = finalCudaPackages.flags // {
cudaComputeCapabilityToName = finalCudaPackages.flags.cudaCapabilityToName;
dropDot = dropDots;
# cudaComputeCapabilityToName = warn "cudaPackages.flags.cudaComputeCapabilityToName is deprecated, use cudaPackages.flags.cudaCapabilityToName instead" cudaCapabilityToName;
# dropDot = warn "cudaPackages.flags.dropDot is deprecated, use lib.cuda.utils.dropDots instead" dropDots;
};
# backendStdenv = warn "cudaPackages.backendStdenv has been removed, use stdenv instead" final.stdenv;
# cudaVersion = warn "cudaPackages.cudaVersion is deprecated, use cudaPackages.cudaMajorMinorVersion instead" cudaMajorMinorVersion;
# cudaFlags = warn "cudaPackages.cudaFlags is deprecated, use cudaPackages.flags instead" finalCudaPackages.flags;
cudnn_8_9 = throw "cudaPackages.cudnn_8_9 has been removed, use cudaPackages.cudnn instead";
})
]
# Redistributable packages
++ (
let
buildRedistPackages' = buildRedistPackages {
inherit
desiredCudaVariant
finalCudaPackages
hostRedistArch
;
};
in
map (
redistName:
let
manifestVersion = cudaPackagesConfig.redists.${redistName};
redistConfig = cudaConfig.redists.${redistName};
in
buildRedistPackages' {
inherit redistName;
callPackageOverriders = redistConfig.versionedOverrides.${manifestVersion} or { };
manifest = redistConfig.versionedManifests.${manifestVersion};
}
) (attrNames cudaPackagesConfig.redists)
)
# CUDA version-specific packages
++ map (
directory:
packagesFromDirectoryRecursive {
inherit (finalCudaPackages) callPackage;
inherit directory;
}
) cudaPackagesConfig.packagesDirectories
);
in
mkCudaPackagesScope final.newScope (
# User additions are included through final.cudaPackagesExtensions
extends (composeManyExtensions final.cudaPackagesExtensions) cudaPackagesFun
);
in
# General configuration
{
inherit lib;
# For inspecting the results of the module system evaluation.
cudaConfig = dontRecurseIntoAttrs cudaConfig // {
__attrsFailEvaluation = true;
};
# For changing the manifests available.
cudaModules = [ ];
# For adding packages in an ad-hoc manner.
cudaPackagesExtensions = [ ];
}
# Package sets
// {
# We cannot add top-level attributes dependent on the fixed point, but we can add them within an attribute set!
cudaPackagesVersions = mapAttrs' (cudaMajorMinorPatchVersion: _: {
name = "cudaPackages_${replaceStrings [ "." ] [ "_" ] cudaMajorMinorPatchVersion}";
value = packageSetBuilder cudaMajorMinorPatchVersion;
}) cudaConfig.cudaPackages;
# Aliases
# NOTE: No way to automate this as presence or absence of attributes depends on the fixed point, which causes
# infinite recursion.
inherit (final.cudaPackagesVersions)
cudaPackages_12_2_2
cudaPackages_12_6_3
;
cudaPackages_12_2 = final.cudaPackages_12_2_2;
cudaPackages_12_6 = final.cudaPackages_12_6_3;
cudaPackages_12 = final.cudaPackages_12_6;
cudaPackages =
final.cudaPackagesVersions."cudaPackages_${
replaceStrings [ "." ] [ "_" ] cudaConfig.defaultCudaPackagesVersion
}";
}
# Nixpkgs package sets matrixed by real architecture (e.g., `sm_90a`).
# TODO(@connorbaker): Yes, it is computationally expensive to call final.extend.
# No, I can't think of a different way to force re-evaluation of the fixed point.
// {
pkgsCuda = mapAttrs' (cudaCapability: _: {
name = mkRealArchitecture cudaCapability;
value = dontRecurseIntoAttrs (
final.extend (
_: prev': {
__attrsFailEvaluation = true;
config = prev'.config // {
cudaCapabilities = [ cudaCapability ];
};
}
)
);
}) cudaConfig.data.gpus;
}
# Upstreamable packages
// packagesFromDirectoryRecursive {
inherit (final) callPackage;
directory = ./upstreamable-packages;
}
# Package fixes
// {
openmpi = prev.openmpi.override {
# The configure flag openmpi takes expects cuda_cudart to be joined.
cudaPackages = final.cudaPackages // {
cuda_cudart = final.symlinkJoin {
name = "cuda_cudart_joined";
paths = map (
output: final.cudaPackages.cuda_cudart.${output}
) final.cudaPackages.cuda_cudart.outputs;
};
};
};
}