lol
1{
2 type,
3 version,
4 srcs,
5 commonPackages ? null,
6 hostPackages ? null,
7 targetPackages ? null,
8 runtime ? null,
9 aspnetcore ? null,
10}:
11
12assert builtins.elem type [
13 "aspnetcore"
14 "runtime"
15 "sdk"
16];
17assert
18 if type == "sdk" then
19 commonPackages != null
20 && hostPackages != null
21 && targetPackages != null
22 && runtime != null
23 && aspnetcore != null
24 else
25 true;
26
27{
28 lib,
29 stdenv,
30 fetchurl,
31 writeText,
32 autoPatchelfHook,
33 makeWrapper,
34 libunwind,
35 icu,
36 libuuid,
37 zlib,
38 libkrb5,
39 openssl,
40 curl,
41 lttng-ust_2_12,
42 testers,
43 runCommand,
44 writeShellScript,
45 mkNugetDeps,
46 callPackage,
47 systemToDotnetRid,
48 xmlstarlet,
49}:
50
51let
52 pname =
53 if type == "aspnetcore" then
54 "aspnetcore-runtime"
55 else if type == "runtime" then
56 "dotnet-runtime"
57 else
58 "dotnet-sdk";
59
60 descriptions = {
61 aspnetcore = "ASP.NET Core Runtime ${version}";
62 runtime = ".NET Runtime ${version}";
63 sdk = ".NET SDK ${version}";
64 };
65
66 mkWrapper = callPackage ./wrapper.nix { };
67
68 hostRid = systemToDotnetRid stdenv.hostPlatform.system;
69 targetRid = systemToDotnetRid stdenv.targetPlatform.system;
70
71 sigtool = callPackage ./sigtool.nix { };
72 signAppHost = callPackage ./sign-apphost.nix { };
73
74 hasILCompiler = lib.versionAtLeast version (if hostRid == "osx-arm64" then "8" else "7");
75
76 extraTargets = writeText "extra.targets" (
77 ''
78 <Project>
79 ''
80 + lib.optionalString hasILCompiler ''
81 <ItemGroup>
82 <CustomLinkerArg Include="-Wl,-rpath,'${
83 lib.makeLibraryPath [
84 icu
85 zlib
86 openssl
87 ]
88 }'" />
89 </ItemGroup>
90 ''
91 + lib.optionalString stdenv.hostPlatform.isDarwin ''
92 <Import Project="${signAppHost}" />
93 ''
94 + ''
95 </Project>
96 ''
97 );
98
99in
100mkWrapper type (
101 stdenv.mkDerivation (finalAttrs: {
102 inherit pname version;
103
104 # Some of these dependencies are `dlopen()`ed.
105 nativeBuildInputs =
106 [
107 makeWrapper
108 ]
109 ++ lib.optional stdenv.hostPlatform.isLinux autoPatchelfHook
110 ++ lib.optionals (type == "sdk" && stdenv.hostPlatform.isDarwin) [
111 xmlstarlet
112 sigtool
113 ];
114
115 buildInputs = [
116 stdenv.cc.cc
117 zlib
118 icu
119 libkrb5
120 curl
121 xmlstarlet
122 ] ++ lib.optional stdenv.hostPlatform.isLinux lttng-ust_2_12;
123
124 src = fetchurl (
125 srcs.${hostRid} or (throw "Missing source (url and hash) for host RID: ${hostRid}")
126 );
127
128 sourceRoot = ".";
129
130 postPatch =
131 if type == "sdk" then
132 (
133 ''
134 xmlstarlet ed \
135 --inplace \
136 -s //_:Project -t elem -n Import \
137 -i \$prev -t attr -n Project -v "${extraTargets}" \
138 sdk/*/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets
139 ''
140 + lib.optionalString (stdenv.hostPlatform.isDarwin && lib.versionOlder version "10") ''
141 codesign --remove-signature packs/Microsoft.NETCore.App.Host.osx-*/*/runtimes/osx-*/native/{apphost,singlefilehost}
142 ''
143 )
144 else
145 null;
146
147 dontPatchELF = true;
148 noDumpEnvVars = true;
149
150 installPhase = ''
151 runHook preInstall
152
153 mkdir -p $out/share/doc/$pname/$version
154 mv LICENSE.txt $out/share/doc/$pname/$version/
155 mv ThirdPartyNotices.txt $out/share/doc/$pname/$version/
156
157 mkdir -p $out/share/dotnet
158 cp -r ./ $out/share/dotnet
159
160 mkdir -p $out/bin
161 ln -s $out/share/dotnet/dotnet $out/bin/dotnet
162
163 runHook postInstall
164 '';
165
166 # Tell autoPatchelf about runtime dependencies.
167 # (postFixup phase is run before autoPatchelfHook.)
168 postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
169 patchelf \
170 --add-needed libicui18n.so \
171 --add-needed libicuuc.so \
172 $out/share/dotnet/shared/Microsoft.NETCore.App/*/libcoreclr.so \
173 $out/share/dotnet/shared/Microsoft.NETCore.App/*/*System.Globalization.Native.so \
174 $out/share/dotnet/packs/Microsoft.NETCore.App.Host.${hostRid}/*/runtimes/${hostRid}/native/*host
175 patchelf \
176 --add-needed libgssapi_krb5.so \
177 $out/share/dotnet/shared/Microsoft.NETCore.App/*/*System.Net.Security.Native.so \
178 $out/share/dotnet/packs/Microsoft.NETCore.App.Host.${hostRid}/*/runtimes/${hostRid}/native/*host
179 patchelf \
180 --add-needed libssl.so \
181 $out/share/dotnet/shared/Microsoft.NETCore.App/*/*System.Security.Cryptography.Native.OpenSsl.so \
182 $out/share/dotnet/packs/Microsoft.NETCore.App.Host.${hostRid}/*/runtimes/${hostRid}/native/*host
183 '';
184
185 # fixes: Could not load ICU data. UErrorCode: 2
186 propagatedSandboxProfile = lib.optionalString stdenv.hostPlatform.isDarwin ''
187 (allow file-read* (subpath "/usr/share/icu"))
188 (allow file-read* (subpath "/private/var/db/mds/system"))
189 (allow mach-lookup (global-name "com.apple.SecurityServer")
190 (global-name "com.apple.system.opendirectoryd.membership"))
191 '';
192
193 passthru =
194 {
195 inherit icu hasILCompiler;
196 }
197 // lib.optionalAttrs (type == "sdk") (
198 let
199 # force evaluation of the SDK package to ensure evaluation failures
200 # (e.g. due to vulnerabilities) propagate to the nuget packages
201 forceSDKEval = builtins.seq finalAttrs.finalPackage.drvPath;
202 in
203 {
204 packages = map forceSDKEval (
205 commonPackages ++ hostPackages.${hostRid} ++ targetPackages.${targetRid}
206 );
207 targetPackages = lib.mapAttrs (_: map forceSDKEval) targetPackages;
208 inherit runtime aspnetcore;
209
210 updateScript =
211 let
212 majorVersion = lib.concatStringsSep "." (lib.take 2 (lib.splitVersion version));
213 in
214 [
215 ./update.sh
216 majorVersion
217 ];
218 }
219 );
220
221 meta = with lib; {
222 description = builtins.getAttr type descriptions;
223 homepage = "https://dotnet.github.io/";
224 license = licenses.mit;
225 maintainers = with maintainers; [
226 kuznero
227 mdarocha
228 corngood
229 ];
230 mainProgram = "dotnet";
231 platforms = lib.filter (
232 platform:
233 let
234 e = builtins.tryEval (systemToDotnetRid platform);
235 in
236 e.success && srcs ? "${e.value}"
237 ) lib.platforms.all;
238 sourceProvenance = with lib.sourceTypes; [
239 binaryBytecode
240 binaryNativeCode
241 ];
242 knownVulnerabilities =
243 lib.optionals
244 (lib.elem (lib.head (lib.splitVersion version)) [
245 "6"
246 "7"
247 ])
248 [
249 "Dotnet SDK ${version} is EOL, please use 8.0 (LTS) or 9.0 (Current)"
250 ];
251 };
252 })
253)