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