at master 6.7 kB view raw
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 makeWrapper 107 ] 108 ++ lib.optional stdenv.hostPlatform.isLinux autoPatchelfHook 109 ++ lib.optionals (type == "sdk" && stdenv.hostPlatform.isDarwin) [ 110 xmlstarlet 111 sigtool 112 ]; 113 114 buildInputs = [ 115 stdenv.cc.cc 116 zlib 117 icu 118 libkrb5 119 curl 120 xmlstarlet 121 ] 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 inherit icu hasILCompiler; 195 } 196 // lib.optionalAttrs (type == "sdk") ( 197 let 198 # force evaluation of the SDK package to ensure evaluation failures 199 # (e.g. due to vulnerabilities) propagate to the nuget packages 200 forceSDKEval = builtins.seq finalAttrs.finalPackage.drvPath; 201 in 202 { 203 packages = map forceSDKEval ( 204 commonPackages ++ hostPackages.${hostRid} ++ targetPackages.${targetRid} 205 ); 206 targetPackages = lib.mapAttrs (_: map forceSDKEval) targetPackages; 207 inherit runtime aspnetcore; 208 209 updateScript = 210 let 211 majorVersion = lib.concatStringsSep "." (lib.take 2 (lib.splitVersion version)); 212 in 213 [ 214 ./update.sh 215 majorVersion 216 ]; 217 } 218 ); 219 220 meta = with lib; { 221 description = builtins.getAttr type descriptions; 222 homepage = "https://dotnet.github.io/"; 223 license = licenses.mit; 224 maintainers = with maintainers; [ 225 kuznero 226 mdarocha 227 corngood 228 ]; 229 mainProgram = "dotnet"; 230 platforms = lib.filter ( 231 platform: 232 let 233 e = builtins.tryEval (systemToDotnetRid platform); 234 in 235 e.success && srcs ? "${e.value}" 236 ) lib.platforms.all; 237 sourceProvenance = with lib.sourceTypes; [ 238 binaryBytecode 239 binaryNativeCode 240 ]; 241 knownVulnerabilities = 242 lib.optionals 243 (lib.elem (lib.head (lib.splitVersion version)) [ 244 "6" 245 "7" 246 ]) 247 [ 248 "Dotnet SDK ${version} is EOL, please use 8.0 (LTS) or 9.0 (Current)" 249 ]; 250 }; 251 }) 252)