mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-02-19 17:39:34 +00:00
buildDotnet.nix: refactor
This commit is contained in:
parent
c32264ef79
commit
a65cc6346d
|
@ -2,6 +2,7 @@
|
||||||
, version
|
, version
|
||||||
, sha512
|
, sha512
|
||||||
}:
|
}:
|
||||||
|
|
||||||
assert builtins.elem type [ "aspnetcore" "netcore" "sdk"];
|
assert builtins.elem type [ "aspnetcore" "netcore" "sdk"];
|
||||||
{ stdenv
|
{ stdenv
|
||||||
, fetchurl
|
, fetchurl
|
||||||
|
@ -11,64 +12,66 @@ assert builtins.elem type [ "aspnetcore" "netcore" "sdk"];
|
||||||
, libuuid
|
, libuuid
|
||||||
, zlib
|
, zlib
|
||||||
, curl
|
, curl
|
||||||
}:
|
}:
|
||||||
let pname = if type == "aspnetcore" then "aspnetcore-runtime" else if type == "netcore" then "dotnet-runtime" else "dotnet-sdk";
|
|
||||||
platform = if stdenv.isDarwin then "osx" else "linux";
|
let
|
||||||
suffix = {
|
pname = if type == "aspnetcore" then "aspnetcore-runtime" else if type == "netcore" then "dotnet-runtime" else "dotnet-sdk";
|
||||||
x86_64-linux = "x64";
|
platform = if stdenv.isDarwin then "osx" else "linux";
|
||||||
aarch64-linux = "arm64";
|
suffix = {
|
||||||
x86_64-darwin = "x64";
|
x86_64-linux = "x64";
|
||||||
}."${stdenv.hostPlatform.system}" or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
|
aarch64-linux = "arm64";
|
||||||
urls = {
|
x86_64-darwin = "x64";
|
||||||
aspnetcore = "https://dotnetcli.azureedge.net/dotnet/aspnetcore/Runtime/${version}/${pname}-${version}-${platform}-${suffix}.tar.gz";
|
}."${stdenv.hostPlatform.system}" or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
|
||||||
netcore = "https://dotnetcli.azureedge.net/dotnet/Runtime/${version}/${pname}-${version}-${platform}-${suffix}.tar.gz";
|
urls = {
|
||||||
sdk = "https://dotnetcli.azureedge.net/dotnet/Sdk/${version}/${pname}-${version}-${platform}-${suffix}.tar.gz";
|
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";
|
||||||
descriptions = {
|
sdk = "https://dotnetcli.azureedge.net/dotnet/Sdk/${version}/${pname}-${version}-${platform}-${suffix}.tar.gz";
|
||||||
aspnetcore = "ASP .NET Core runtime ${version}";
|
};
|
||||||
netcore = ".NET Core runtime ${version}";
|
descriptions = {
|
||||||
sdk = ".NET SDK ${version}";
|
aspnetcore = "ASP .NET Core runtime ${version}";
|
||||||
};
|
netcore = ".NET Core runtime ${version}";
|
||||||
|
sdk = ".NET SDK ${version}";
|
||||||
|
};
|
||||||
in stdenv.mkDerivation rec {
|
in stdenv.mkDerivation rec {
|
||||||
inherit pname version;
|
inherit pname version;
|
||||||
|
|
||||||
rpath = stdenv.lib.makeLibraryPath [ stdenv.cc.cc libunwind libuuid icu openssl zlib curl ];
|
rpath = stdenv.lib.makeLibraryPath [ stdenv.cc.cc libunwind libuuid icu openssl zlib curl ];
|
||||||
|
|
||||||
src = fetchurl {
|
src = fetchurl {
|
||||||
url = builtins.getAttr type urls;
|
url = builtins.getAttr type urls;
|
||||||
sha512 = sha512."${stdenv.hostPlatform.system}" or (throw "Missing hash for host system: ${stdenv.hostPlatform.system}");
|
sha512 = sha512."${stdenv.hostPlatform.system}" or (throw "Missing hash for host system: ${stdenv.hostPlatform.system}");
|
||||||
};
|
};
|
||||||
|
|
||||||
sourceRoot = ".";
|
sourceRoot = ".";
|
||||||
|
|
||||||
dontPatchELF = true;
|
dontPatchELF = true;
|
||||||
noDumpEnvVars = true;
|
noDumpEnvVars = true;
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
runHook preInstall
|
runHook preInstall
|
||||||
mkdir -p $out/bin
|
mkdir -p $out/bin
|
||||||
cp -r ./ $out
|
cp -r ./ $out
|
||||||
ln -s $out/dotnet $out/bin/dotnet
|
ln -s $out/dotnet $out/bin/dotnet
|
||||||
runHook postInstall
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
|
|
||||||
postFixup = stdenv.lib.optionalString stdenv.isLinux ''
|
postFixup = stdenv.lib.optionalString stdenv.isLinux ''
|
||||||
patchelf --set-interpreter "${stdenv.cc.bintools.dynamicLinker}" $out/dotnet
|
patchelf --set-interpreter "${stdenv.cc.bintools.dynamicLinker}" $out/dotnet
|
||||||
patchelf --set-rpath "${rpath}" $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 "*.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}' {} \;
|
find $out -type f -name "apphost" -exec patchelf --set-interpreter "${stdenv.cc.bintools.dynamicLinker}" --set-rpath '$ORIGIN:${rpath}' {} \;
|
||||||
'';
|
'';
|
||||||
|
|
||||||
doInstallCheck = true;
|
doInstallCheck = true;
|
||||||
installCheckPhase = ''
|
installCheckPhase = ''
|
||||||
$out/bin/dotnet --info
|
$out/bin/dotnet --info
|
||||||
'';
|
'';
|
||||||
|
|
||||||
meta = with stdenv.lib; {
|
meta = with stdenv.lib; {
|
||||||
homepage = "https://dotnet.github.io/";
|
homepage = "https://dotnet.github.io/";
|
||||||
description = builtins.getAttr type descriptions;
|
description = builtins.getAttr type descriptions;
|
||||||
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ];
|
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ];
|
||||||
maintainers = with maintainers; [ kuznero ];
|
maintainers = with maintainers; [ kuznero ];
|
||||||
license = licenses.mit;
|
license = licenses.mit;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue