nixpkgs/pkgs/development/compilers/dotnet/build-dotnet.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

168 lines
4.2 KiB
Nix
Raw Normal View History

{ type
, version
, srcs
, packages ? null
}:
2020-07-16 21:02:04 +00:00
2022-05-19 01:41:08 +00:00
assert builtins.elem type [ "aspnetcore" "runtime" "sdk" ];
assert if type == "sdk" then packages != null else true;
{ lib
, stdenv
, fetchurl
, writeText
2022-05-19 01:41:08 +00:00
, autoPatchelfHook
, makeWrapper
, libunwind
, icu
, libuuid
, zlib
, libkrb5
, curl
2021-04-05 16:01:43 +00:00
, lttng-ust_2_12
2022-09-09 10:18:26 +00:00
, testers
, runCommand
, writeShellScript
, mkNugetDeps
2020-07-16 21:02:04 +00:00
}:
let
2022-05-19 01:41:08 +00:00
pname =
if type == "aspnetcore" then
"aspnetcore-runtime"
else if type == "runtime" then
"dotnet-runtime"
else
"dotnet-sdk";
2020-07-16 21:02:04 +00:00
descriptions = {
aspnetcore = "ASP.NET Core Runtime ${version}";
runtime = ".NET Runtime ${version}";
2020-07-16 21:02:04 +00:00
sdk = ".NET SDK ${version}";
};
packageDeps = if type == "sdk" then mkNugetDeps {
name = "${pname}-${version}-deps";
nugetDeps = packages;
} else null;
2022-05-19 01:41:08 +00:00
in
2022-09-09 10:18:26 +00:00
stdenv.mkDerivation (finalAttrs: rec {
2020-07-16 21:02:04 +00:00
inherit pname version;
2021-04-05 16:01:43 +00:00
# Some of these dependencies are `dlopen()`ed.
2022-05-19 01:41:08 +00:00
nativeBuildInputs = [
makeWrapper
2022-07-17 20:34:29 +00:00
] ++ lib.optional stdenv.isLinux autoPatchelfHook;
2022-05-19 01:41:08 +00:00
buildInputs = [
stdenv.cc.cc
zlib
icu
libkrb5
curl
] ++ lib.optional stdenv.isLinux lttng-ust_2_12;
2022-05-19 01:41:08 +00:00
src = fetchurl (
srcs."${stdenv.hostPlatform.system}" or (throw
"Missing source (url and hash) for host system: ${stdenv.hostPlatform.system}")
);
2020-07-16 21:02:04 +00:00
sourceRoot = ".";
2020-07-16 21:02:04 +00:00
dontPatchELF = true;
noDumpEnvVars = true;
2020-07-16 21:02:04 +00:00
installPhase = ''
runHook preInstall
2020-07-16 21:02:04 +00:00
mkdir -p $out/bin
cp -r ./ $out
mkdir -p $out/share/doc/$pname/$version
mv $out/LICENSE.txt $out/share/doc/$pname/$version/
mv $out/ThirdPartyNotices.txt $out/share/doc/$pname/$version/
2020-07-16 21:02:04 +00:00
ln -s $out/dotnet $out/bin/dotnet
2020-07-16 21:02:04 +00:00
runHook postInstall
'';
2020-07-16 21:02:04 +00:00
doInstallCheck = true;
installCheckPhase = ''
$out/bin/dotnet --info
'';
# Tell autoPatchelf about runtime dependencies.
# (postFixup phase is run before autoPatchelfHook.)
postFixup = lib.optionalString stdenv.isLinux ''
patchelf \
--add-needed libicui18n.so \
--add-needed libicuuc.so \
$out/shared/Microsoft.NETCore.App/*/libcoreclr.so \
$out/shared/Microsoft.NETCore.App/*/*System.Globalization.Native.so \
$out/packs/Microsoft.NETCore.App.Host.linux-x64/*/runtimes/linux-x64/native/singlefilehost
patchelf \
--add-needed libgssapi_krb5.so \
$out/shared/Microsoft.NETCore.App/*/*System.Net.Security.Native.so \
$out/packs/Microsoft.NETCore.App.Host.linux-x64/*/runtimes/linux-x64/native/singlefilehost
patchelf \
--add-needed libssl.so \
$out/shared/Microsoft.NETCore.App/*/*System.Security.Cryptography.Native.OpenSsl.so \
$out/packs/Microsoft.NETCore.App.Host.linux-x64/*/runtimes/linux-x64/native/singlefilehost
'';
setupHook = writeText "dotnet-setup-hook" ''
if [ ! -w "$HOME" ]; then
export HOME=$(mktemp -d) # Dotnet expects a writable home directory for its configuration files
fi
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 # Dont try to expand NuGetFallbackFolder to disk
export DOTNET_NOLOGO=1 # Disables the welcome message
export DOTNET_CLI_TELEMETRY_OPTOUT=1
'';
passthru = {
inherit icu;
packages = packageDeps;
updateScript =
if type == "sdk" then
let
majorVersion =
with lib;
concatStringsSep "." (take 2 (splitVersion version));
in
writeShellScript "update-dotnet-${majorVersion}" ''
pushd pkgs/development/compilers/dotnet
exec ${./update.sh} "${majorVersion}"
'' else null;
2022-09-09 10:18:26 +00:00
tests = {
version = testers.testVersion {
package = finalAttrs.finalPackage;
};
smoke-test = runCommand "dotnet-sdk-smoke-test" {
nativeBuildInputs = [ finalAttrs.finalPackage ];
} ''
HOME=$(pwd)/fake-home
dotnet new console
dotnet build
output="$(dotnet run)"
# yes, older SDKs omit the comma
[[ "$output" =~ Hello,?\ World! ]] && touch "$out"
'';
};
2022-05-19 01:41:08 +00:00
};
meta = with lib; {
2020-07-16 21:02:04 +00:00
description = builtins.getAttr type descriptions;
homepage = "https://dotnet.github.io/";
2020-07-16 21:02:04 +00:00
license = licenses.mit;
2022-05-15 08:54:10 +00:00
maintainers = with maintainers; [ kuznero mdarocha ];
mainProgram = "dotnet";
2022-09-15 22:40:42 +00:00
platforms = attrNames srcs;
2020-07-16 21:02:04 +00:00
};
2022-09-09 10:18:26 +00:00
})