Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ lib, stdenv, fetchurl, vscode-utils, extractNuGet
2, icu, curl, openssl, liburcu, 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 liburcu-0-12 = liburcu.overrideAttrs (oldAttrs: rec {
16 version = "0.12.2";
17 src = fetchurl {
18 url = "https://lttng.org/files/urcu/userspace-rcu-${version}.tar.bz2";
19 sha256 = "0yx69kbx9zd6ayjzvwvglilhdnirq4f1x1sdv33jy8bc9wgc3vsf";
20 };
21 });
22
23 lttng-ust-2-10 = (lttng-ust.override {
24 liburcu = liburcu-0-12;
25 }).overrideAttrs (oldAttrs: rec {
26 version = "2.10.5";
27 src = fetchurl {
28 url = "https://lttng.org/files/lttng-ust/lttng-ust-${version}.tar.bz2";
29 sha256 = "0ddwk0nl28bkv2xb78gz16a2bvlpfbjmzwfbgwf5p1cq46dyvy86";
30 };
31 });
32
33 pythonDefaultsTo = if pythonUseFixed then "${python3}/bin/python" else "python";
34 ctagsDefaultsTo = if ctagsUseFixed then "${ctags}/bin/ctags" else "ctags";
35
36 # The arch tag comes from 'PlatformName' defined here:
37 # https://github.com/Microsoft/vscode-python/blob/master/src/client/activation/types.ts
38 arch =
39 if stdenv.isLinux && stdenv.isx86_64 then "linux-x64"
40 else if stdenv.isDarwin then "osx-x64"
41 else throw "Only x86_64 Linux and Darwin are supported.";
42
43 languageServerSha256 = {
44 linux-x64 = "1pmj5pb4xylx4gdx4zgmisn0si59qx51n2m1bh7clv29q6biw05n";
45 osx-x64 = "0ishiy1z9dghj4ryh95vy8rw0v7q4birdga2zdb4a8am31wmp94b";
46 }.${arch};
47
48 # version is languageServerVersion in the package.json
49 languageServer = extractNuGet rec {
50 name = "Python-Language-Server";
51 version = "0.5.30";
52
53 src = fetchurl {
54 url = "https://pvsc.azureedge.net/python-language-server-stable/${name}-${arch}.${version}.nupkg";
55 sha256 = languageServerSha256;
56 };
57 };
58in vscode-utils.buildVscodeMarketplaceExtension rec {
59 mktplcRef = {
60 name = "python";
61 publisher = "ms-python";
62 version = "2021.11.1422169775";
63 };
64
65 vsix = fetchurl {
66 name = "${mktplcRef.publisher}-${mktplcRef.name}.zip";
67 url = "https://github.com/microsoft/vscode-python/releases/download/${mktplcRef.version}/ms-python-release.vsix";
68 sha256 = "sha256-Y8Wbpuieca/edIWqgq+lGSUMABOGvO/GuujGlEGmoKs=";
69 };
70
71 buildInputs = [
72 icu
73 curl
74 openssl
75 lttng-ust-2-10
76 musl
77 ];
78
79 nativeBuildInputs = [
80 autoPatchelfHook
81 python3.pkgs.wrapPython
82 ];
83
84 pythonPath = with python3.pkgs; [
85 setuptools
86 ];
87
88 postPatch = ''
89 # Patch `packages.json` so that nix's *python* is used as default value for `python.pythonPath`.
90 substituteInPlace "./package.json" \
91 --replace "\"default\": \"python\"" "\"default\": \"${pythonDefaultsTo}\""
92
93 # Patch `packages.json` so that nix's *ctags* is used as default value for `python.workspaceSymbols.ctagsPath`.
94 substituteInPlace "./package.json" \
95 --replace "\"default\": \"ctags\"" "\"default\": \"${ctagsDefaultsTo}\""
96
97 # Similar cleanup to what's done in the `debugpy` python package.
98 # This prevent our autopatchelf logic to bark on unsupported binaries (`attach_x86.so`
99 # was problematic) but also should make our derivation less heavy.
100 (
101 cd pythonFiles/lib/python/debugpy/_vendored/pydevd/pydevd_attach_to_process
102 declare kept_aside="${{
103 "x86_64-linux" = "attach_linux_amd64.so";
104 }.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}")}"
105 mv "$kept_aside" "$kept_aside.hidden"
106 rm *.so *.dylib *.dll *.exe *.pdb
107 mv "$kept_aside.hidden" "$kept_aside"
108 )
109 '';
110
111 postInstall = ''
112 mkdir -p "$out/$installPrefix/languageServer.${languageServer.version}"
113 cp -R --no-preserve=ownership ${languageServer}/* "$out/$installPrefix/languageServer.${languageServer.version}"
114 chmod -R +wx "$out/$installPrefix/languageServer.${languageServer.version}"
115
116 patchPythonScript "$out/$installPrefix/pythonFiles/lib/python/isort/main.py"
117 '';
118
119 meta = with lib; {
120 license = licenses.mit;
121 platforms = [ "x86_64-linux" ];
122 maintainers = [ maintainers.jraygauthier ];
123 };
124}