1{ lib, stdenv 2, fetchFromGitHub 3, fetchurl 4, makeWrapper 5, dotnet-sdk_3 6, openssl 7, icu 8, patchelf 9, Nuget 10}: 11 12let deps = import ./deps.nix { inherit fetchurl; }; 13 version = "2021-05-20"; 14 15 # Build the nuget source needed for the later build all by itself 16 # since it's a time-consuming step that only depends on ./deps.nix. 17 # This makes it easier to experiment with the main build. 18 nugetSource = stdenv.mkDerivation { 19 pname = "python-language-server-nuget-deps"; 20 inherit version; 21 22 dontUnpack = true; 23 24 nativeBuildInputs = [ Nuget ]; 25 26 buildPhase = '' 27 export HOME=$(mktemp -d) 28 29 mkdir -p $out/lib 30 31 # disable default-source so nuget does not try to download from online-repo 32 nuget sources Disable -Name "nuget.org" 33 # add all dependencies to the source 34 for package in ${toString deps}; do 35 nuget add $package -Source $out/lib 36 done 37 ''; 38 39 dontInstall = true; 40 }; 41 42in 43 44stdenv.mkDerivation { 45 pname = "python-language-server"; 46 inherit version; 47 48 src = fetchFromGitHub { 49 owner = "microsoft"; 50 repo = "python-language-server"; 51 rev = "86825796eae15d4d46919bc6e32f1197196ba1b3"; 52 sha256 = "sha256-izDE7Oil9g47Jf3eHPtW5coNixF71t9i0oYSuelakCo="; 53 }; 54 55 buildInputs = [dotnet-sdk_3 openssl icu]; 56 57 nativeBuildInputs = [ 58 Nuget 59 makeWrapper 60 patchelf 61 ]; 62 63 buildPhase = '' 64 runHook preBuild 65 66 mkdir home 67 export HOME=$(mktemp -d) 68 export DOTNET_CLI_TELEMETRY_OPTOUT=1 69 export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 70 71 pushd src 72 nuget sources Disable -Name "nuget.org" 73 dotnet restore --source ${nugetSource}/lib -r linux-x64 74 popd 75 76 pushd src/LanguageServer/Impl 77 dotnet publish --no-restore -c Release -r linux-x64 78 popd 79 80 runHook postBuild 81 ''; 82 83 installPhase = '' 84 runHook preInstall 85 86 mkdir -p $out 87 cp -r output/bin/Release/linux-x64/publish $out/lib 88 89 mkdir $out/bin 90 makeWrapper $out/lib/Microsoft.Python.LanguageServer $out/bin/python-language-server 91 92 runHook postInstall 93 ''; 94 95 postFixup = '' 96 patchelf --set-rpath ${icu}/lib $out/lib/System.Globalization.Native.so 97 patchelf --set-rpath ${openssl.out}/lib $out/lib/System.Security.Cryptography.Native.OpenSsl.so 98 ''; 99 100 # If we don't disable stripping, the executable fails to start with an error about being unable 101 # to find some of the packaged DLLs. 102 dontStrip = true; 103 104 meta = with lib; { 105 description = "Microsoft Language Server for Python"; 106 homepage = "https://github.com/microsoft/python-language-server"; 107 license = licenses.asl20; 108 maintainers = with maintainers; [ thomasjm ]; 109 platforms = [ "x86_64-linux" ]; 110 }; 111}