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

93 lines
2.4 KiB
Nix
Raw Normal View History

{ type
, version
, sha512
}:
2020-07-16 22:02:04 +01:00
assert builtins.elem type [ "aspnetcore" "netcore" "sdk"];
{ lib, stdenv
, fetchurl
, libunwind
, openssl
, icu
, libuuid
, zlib
, curl
2020-07-16 22:02:04 +01:00
}:
let
2020-07-16 22:23:49 +01:00
pname = if type == "aspnetcore" then
"aspnetcore-runtime"
else if type == "netcore" then
"dotnet-runtime"
else
"dotnet-sdk";
2020-07-16 22:02:04 +01:00
platform = if stdenv.isDarwin then "osx" else "linux";
suffix = {
2020-07-16 22:23:49 +01:00
x86_64-linux = "x64";
2020-07-16 22:02:04 +01:00
aarch64-linux = "arm64";
x86_64-darwin = "x64";
2020-07-16 22:23:49 +01:00
}."${stdenv.hostPlatform.system}" or (throw
"Unsupported system: ${stdenv.hostPlatform.system}");
2020-07-16 22:02:04 +01:00
urls = {
aspnetcore = "https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/${version}/${pname}-${version}-${platform}-${suffix}.tar.gz";
netcore = "https://dotnetcli.azureedge.net/dotnet/Runtime/${version}/${pname}-${version}-${platform}-${suffix}.tar.gz";
sdk = "https://dotnetcli.azureedge.net/dotnet/Sdk/${version}/${pname}-${version}-${platform}-${suffix}.tar.gz";
};
descriptions = {
aspnetcore = "ASP .NET Core runtime ${version}";
netcore = ".NET Core runtime ${version}";
sdk = ".NET SDK ${version}";
};
in stdenv.mkDerivation rec {
2020-07-16 22:02:04 +01:00
inherit pname version;
rpath = lib.makeLibraryPath [
2020-07-16 22:23:49 +01:00
curl
icu
libunwind
libuuid
openssl
stdenv.cc.cc
zlib
];
2020-07-16 22:02:04 +01:00
src = fetchurl {
url = builtins.getAttr type urls;
2020-07-16 22:23:49 +01:00
sha512 = sha512."${stdenv.hostPlatform.system}" or (throw
"Missing hash for host system: ${stdenv.hostPlatform.system}");
2020-07-16 22:02:04 +01:00
};
2020-07-16 22:02:04 +01:00
sourceRoot = ".";
2020-07-16 22:02:04 +01:00
dontPatchELF = true;
noDumpEnvVars = true;
2020-07-16 22:02:04 +01:00
installPhase = ''
runHook preInstall
mkdir -p $out/bin
cp -r ./ $out
ln -s $out/dotnet $out/bin/dotnet
runHook postInstall
'';
postFixup = lib.optionalString stdenv.isLinux ''
2020-07-16 22:02:04 +01:00
patchelf --set-interpreter "${stdenv.cc.bintools.dynamicLinker}" $out/dotnet
patchelf --set-rpath "${rpath}" $out/dotnet
find $out -type f -name "*.so" -exec patchelf --set-rpath '$ORIGIN:${rpath}' {} \;
find $out -type f -name "apphost" -exec patchelf --set-interpreter "${stdenv.cc.bintools.dynamicLinker}" --set-rpath '$ORIGIN:${rpath}' {} \;
'';
2020-07-16 22:02:04 +01:00
doInstallCheck = true;
installCheckPhase = ''
$out/bin/dotnet --info
'';
meta = with lib; {
2020-07-16 22:02:04 +01:00
homepage = "https://dotnet.github.io/";
description = builtins.getAttr type descriptions;
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ];
maintainers = with maintainers; [ kuznero ];
license = licenses.mit;
};
}