1/*
2 How to combine packages for use in development:
3 dotnetCombined = with dotnetCorePackages; combinePackages [ sdk_9_0 aspnetcore_8_0 ];
4
5 Hashes and urls are retrieved from:
6 https://dotnet.microsoft.com/download/dotnet
7*/
8{
9 lib,
10 config,
11 recurseIntoAttrs,
12 generateSplicesForMkScope,
13 makeScopeWithSplicing',
14 writeScriptBin,
15}:
16
17let
18 pkgs = makeScopeWithSplicing' {
19 otherSplices = generateSplicesForMkScope "dotnetCorePackages";
20 f = (
21 self:
22 let
23 callPackage = self.callPackage;
24
25 fetchNupkg = callPackage ../../../build-support/dotnet/fetch-nupkg { };
26
27 buildDotnet = attrs: callPackage (import ./build-dotnet.nix attrs) { };
28 buildDotnetSdk =
29 version:
30 import version {
31 inherit fetchNupkg;
32 buildAspNetCore = attrs: buildDotnet (attrs // { type = "aspnetcore"; });
33 buildNetRuntime = attrs: buildDotnet (attrs // { type = "runtime"; });
34 buildNetSdk = attrs: buildDotnet (attrs // { type = "sdk"; });
35 };
36
37 ## Files in versions/ are generated automatically by update.sh ##
38 dotnet-bin = lib.mergeAttrsList (
39 map buildDotnetSdk [
40 ./versions/6.0.nix
41 ./versions/7.0.nix
42 ./versions/8.0.nix
43 ./versions/9.0.nix
44 ./versions/10.0.nix
45 ]
46 );
47
48 runtimeIdentifierMap = {
49 "x86_64-linux" = "linux-x64";
50 "aarch64-linux" = "linux-arm64";
51 "x86_64-darwin" = "osx-x64";
52 "aarch64-darwin" = "osx-arm64";
53 "x86_64-windows" = "win-x64";
54 "i686-windows" = "win-x86";
55 };
56
57 in
58 lib.optionalAttrs config.allowAliases (
59 {
60 # EOL
61 sdk_2_1 = throw "Dotnet SDK 2.1 is EOL, please use 8.0 (LTS) or 9.0 (Current)";
62 sdk_2_2 = throw "Dotnet SDK 2.2 is EOL, please use 8.0 (LTS) or 9.0 (Current)";
63 sdk_3_0 = throw "Dotnet SDK 3.0 is EOL, please use 8.0 (LTS) or 9.0 (Current)";
64 sdk_3_1 = throw "Dotnet SDK 3.1 is EOL, please use 8.0 (LTS) or 9.0 (Current)";
65 sdk_5_0 = throw "Dotnet SDK 5.0 is EOL, please use 8.0 (LTS) or 9.0 (Current)";
66 }
67 // dotnet-bin
68 )
69 // lib.mapAttrs' (k: v: lib.nameValuePair "${k}-bin" v) dotnet-bin
70 // {
71 inherit callPackage fetchNupkg buildDotnetSdk;
72
73 generate-dotnet-sdk = writeScriptBin "generate-dotnet-sdk" (
74 # Don't include current nixpkgs in the exposed version. We want to make the script runnable without nixpkgs repo.
75 builtins.replaceStrings [ " -I nixpkgs=./." ] [ "" ] (builtins.readFile ./update.sh)
76 );
77
78 # Convert a "stdenv.hostPlatform.system" to a dotnet RID
79 systemToDotnetRid =
80 system: runtimeIdentifierMap.${system} or (throw "unsupported platform ${system}");
81
82 combinePackages = attrs: callPackage (import ./combine-packages.nix attrs) { };
83
84 patchNupkgs = callPackage ./patch-nupkgs.nix { };
85 nugetPackageHook = callPackage ./nuget-package-hook.nix { };
86 autoPatchcilHook = callPackage ../../../build-support/dotnet/auto-patchcil-hook { };
87
88 buildDotnetModule = callPackage ../../../build-support/dotnet/build-dotnet-module { };
89 buildDotnetGlobalTool = callPackage ../../../build-support/dotnet/build-dotnet-global-tool { };
90
91 mkNugetSource = callPackage ../../../build-support/dotnet/make-nuget-source { };
92 mkNugetDeps = callPackage ../../../build-support/dotnet/make-nuget-deps { };
93 addNuGetDeps = callPackage ../../../build-support/dotnet/add-nuget-deps { };
94
95 dotnet_8 = recurseIntoAttrs (callPackage ./8 { });
96 dotnet_9 = recurseIntoAttrs (callPackage ./9 { });
97 dotnet_10 = recurseIntoAttrs (callPackage ./10 { });
98 }
99 );
100 };
101
102 # combine an SDK with the runtime/packages from a base SDK
103 combineSdk =
104 base: overlay:
105 if (overlay.runtime.version != base.runtime.version) then
106 throw "combineSdk: unable to combine ${overlay.name} with ${base.name} because runtime versions don't match (${overlay.runtime.version} != ${base.runtime.version})"
107 else
108 pkgs.callPackage ./wrapper.nix { } "sdk" (
109 (pkgs.combinePackages [
110 base.runtime
111 base.aspnetcore
112 (overlay.overrideAttrs (old: {
113 passthru = old.passthru // {
114 inherit (base)
115 packages
116 targetPackages
117 ;
118 };
119 }))
120 ]).unwrapped.overrideAttrs
121 (old: {
122 name = overlay.unwrapped.name;
123 # resolve symlinks so DOTNET_ROOT is self-contained
124 postBuild = ''
125 mv "$out"/share/dotnet{,~}
126 cp -Lr "$out"/share/dotnet{~,}
127 rm -r "$out"/share/dotnet~
128 ''
129 + old.postBuild;
130 passthru =
131 old.passthru
132 // (
133 let
134 # if only overlay has a working ILCompiler, use it
135 hostRid = pkgs.systemToDotnetRid base.stdenv.hostPlatform.system;
136 hasILCompiler = base.hasILCompiler || overlay.hasILCompiler;
137 packageName = "runtime.${hostRid}.Microsoft.DotNet.ILCompiler";
138 packages =
139 if !base.hasILCompiler && overlay.hasILCompiler then
140 lib.filter (x: x.pname != packageName) base.packages
141 ++ lib.filter (x: x.pname == packageName) overlay.packages
142 else
143 base.packages;
144 in
145 {
146 inherit hasILCompiler packages;
147 inherit (base)
148 targetPackages
149 runtime
150 aspnetcore
151 ;
152 inherit (overlay.unwrapped)
153 pname
154 version
155 ;
156 }
157 );
158 })
159 );
160
161in
162pkgs
163// rec {
164 # use binary SDK here to avoid downgrading feature band
165 sdk_8_0_1xx = if !pkgs.dotnet_8.vmr.meta.broken then pkgs.dotnet_8.sdk else pkgs.sdk_8_0_1xx-bin;
166 sdk_9_0_1xx = if !pkgs.dotnet_9.vmr.meta.broken then pkgs.dotnet_9.sdk else pkgs.sdk_9_0_1xx-bin;
167 sdk_10_0_1xx =
168 if !pkgs.dotnet_10.vmr.meta.broken then pkgs.dotnet_10.sdk else pkgs.sdk_10_0_1xx-bin;
169 # source-built SDK only exists for _1xx feature band
170 # https://github.com/dotnet/source-build/issues/3667
171 sdk_8_0_3xx = combineSdk sdk_8_0_1xx pkgs.sdk_8_0_3xx-bin;
172 sdk_8_0_4xx = combineSdk sdk_8_0_1xx pkgs.sdk_8_0_4xx-bin;
173 sdk_9_0_3xx = combineSdk sdk_9_0_1xx pkgs.sdk_9_0_3xx-bin;
174 sdk_8_0 = sdk_8_0_4xx;
175 sdk_9_0 = sdk_9_0_3xx;
176 sdk_10_0 = sdk_10_0_1xx;
177 sdk_8_0-source = sdk_8_0_1xx;
178 sdk_9_0-source = sdk_9_0_1xx;
179 sdk_10_0-source = sdk_10_0_1xx;
180 runtime_8_0 = sdk_8_0.runtime;
181 runtime_9_0 = sdk_9_0.runtime;
182 runtime_10_0 = sdk_10_0.runtime;
183 aspnetcore_8_0 = sdk_8_0.aspnetcore;
184 aspnetcore_9_0 = sdk_9_0.aspnetcore;
185 aspnetcore_10_0 = sdk_10_0.aspnetcore;
186}