nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ lib, stdenv, fetchurl, vscode-utils, extractNuGet
2, icu, curl, openssl, lttng-ust, autoPatchelfHook
3, python3, musl
4, pythonUseFixed ? false # When `true`, the python default setting will be fixed to specified.
5 # Use version from `PATH` for default setting otherwise.
6 # Defaults to `false` as we expect it to be project specific most of the time.
7, ctagsUseFixed ? true, ctags # When `true`, the ctags default setting will be fixed to specified.
8 # Use version from `PATH` for default setting otherwise.
9 # Defaults to `true` as usually not defined on a per projet basis.
10}:
11
12assert ctagsUseFixed -> null != ctags;
13
14let
15 pythonDefaultsTo = if pythonUseFixed then "${python3}/bin/python" else "python";
16 ctagsDefaultsTo = if ctagsUseFixed then "${ctags}/bin/ctags" else "ctags";
17
18 # The arch tag comes from 'PlatformName' defined here:
19 # https://github.com/Microsoft/vscode-python/blob/master/src/client/activation/types.ts
20 arch =
21 if stdenv.isLinux && stdenv.isx86_64 then "linux-x64"
22 else if stdenv.isDarwin then "osx-x64"
23 else throw "Only x86_64 Linux and Darwin are supported.";
24
25 languageServerSha256 = {
26 linux-x64 = "1pmj5pb4xylx4gdx4zgmisn0si59qx51n2m1bh7clv29q6biw05n";
27 osx-x64 = "0ishiy1z9dghj4ryh95vy8rw0v7q4birdga2zdb4a8am31wmp94b";
28 }.${arch};
29
30 # version is languageServerVersion in the package.json
31 languageServer = extractNuGet rec {
32 name = "Python-Language-Server";
33 version = "0.5.30";
34
35 src = fetchurl {
36 url = "https://pvsc.azureedge.net/python-language-server-stable/${name}-${arch}.${version}.nupkg";
37 sha256 = languageServerSha256;
38 };
39 };
40in vscode-utils.buildVscodeMarketplaceExtension rec {
41 mktplcRef = {
42 name = "python";
43 publisher = "ms-python";
44 version = "2020.7.96456";
45 };
46
47 vsix = fetchurl {
48 name = "${mktplcRef.publisher}-${mktplcRef.name}.zip";
49 url = "https://github.com/microsoft/vscode-python/releases/download/${mktplcRef.version}/ms-python-release.vsix";
50 sha256 = "0bk2wnbjcraxilzxszl00r799xf3apkfyzpy88xxv87j7787dsm8";
51 };
52
53 buildInputs = [
54 icu
55 curl
56 openssl
57 lttng-ust
58 musl
59 ];
60
61 nativeBuildInputs = [
62 autoPatchelfHook
63 python3.pkgs.wrapPython
64 ];
65
66 pythonPath = with python3.pkgs; [
67 setuptools
68 ];
69
70 postPatch = ''
71 # Patch `packages.json` so that nix's *python* is used as default value for `python.pythonPath`.
72 substituteInPlace "./package.json" \
73 --replace "\"default\": \"python\"" "\"default\": \"${pythonDefaultsTo}\""
74
75 # Patch `packages.json` so that nix's *ctags* is used as default value for `python.workspaceSymbols.ctagsPath`.
76 substituteInPlace "./package.json" \
77 --replace "\"default\": \"ctags\"" "\"default\": \"${ctagsDefaultsTo}\""
78 '';
79
80 postInstall = ''
81 mkdir -p "$out/$installPrefix/languageServer.${languageServer.version}"
82 cp -R --no-preserve=ownership ${languageServer}/* "$out/$installPrefix/languageServer.${languageServer.version}"
83 chmod -R +wx "$out/$installPrefix/languageServer.${languageServer.version}"
84
85 patchPythonScript "$out/$installPrefix/pythonFiles/lib/python/isort/main.py"
86 '';
87
88 meta = with lib; {
89 license = licenses.mit;
90 platforms = [ "x86_64-linux" ];
91 maintainers = [ maintainers.jraygauthier ];
92 };
93}