nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ stdenv, vscode-utils
2, fetchurl, unzip
3, mono, writeScript, runtimeShell
4, jq, clang-tools
5, gdbUseFixed ? true, gdb # The gdb default setting will be fixed to specified. Use version from `PATH` otherwise.
6}:
7
8assert gdbUseFixed -> null != gdb;
9
10/*
11 Note that this version of the extension still has some nix specific issues
12 which could not be fixed merely by patching (inside a C# dll).
13
14 In particular, the debugger requires either gnome-terminal or xterm. However
15 instead of looking for the terminal executable in `PATH`, for any linux platform
16 the dll uses an hardcoded path to one of these.
17
18 So, in order for debugging to work properly, you merely need to create symlinks
19 to one of these terminals at the appropriate location.
20
21 The good news is the the utility library is open source and with some effort
22 we could build a patched version ourselves. See:
23
24 <https://github.com/Microsoft/MIEngine/blob/2885386dc7f35e0f1e44827269341e786361f28e/src/MICore/TerminalLauncher.cs#L156>
25
26 Also, the extension should eventually no longer require an external terminal. See:
27
28 <https://github.com/Microsoft/vscode-cpptools/issues/35>
29
30 Once the symbolic link temporary solution taken, everything shoud run smootly.
31*/
32
33let
34 gdbDefaultsTo = if gdbUseFixed then "${gdb}/bin/gdb" else "gdb";
35
36
37 openDebugAD7Script = writeScript "OpenDebugAD7" ''
38 #!${runtimeShell}
39 BIN_DIR="$(cd "$(dirname "$0")" && pwd -P)"
40 ${if gdbUseFixed
41 then ''
42 export PATH=''${PATH}''${PATH:+:}${gdb}/bin
43 ''
44 else ""}
45 ${mono}/bin/mono $BIN_DIR/bin/OpenDebugAD7.exe $*
46 '';
47in
48
49vscode-utils.buildVscodeMarketplaceExtension rec {
50 mktplcRef = {
51 name = "cpptools";
52 publisher = "ms-vscode";
53 version = "0.29.0";
54 };
55
56 vsix = fetchurl {
57 name = "${mktplcRef.publisher}-${mktplcRef.name}.zip";
58 url = "https://github.com/microsoft/vscode-cpptools/releases/download/${mktplcRef.version}/cpptools-linux.vsix";
59 sha256 = "0qw21wd6hfqrmvyvr2ggydcfsk1hralj5x3s8hhwqyspb7szggxi";
60 };
61
62 buildInputs = [
63 jq
64 ];
65
66 postPatch = ''
67 mv ./package.json ./package_orig.json
68
69 # 1. Add activation events so that the extension is functional. This listing is empty when unpacking the extension but is filled at runtime.
70 # 2. Patch `package.json` so that nix's *gdb* is used as default value for `miDebuggerPath`.
71 cat ./package_orig.json | \
72 jq --slurpfile actEvts ${./package-activation-events.json} '(.activationEvents) = $actEvts[0]' | \
73 jq '(.contributes.debuggers[].configurationAttributes | .attach , .launch | .properties.miDebuggerPath | select(. != null) | select(.default == "/usr/bin/gdb") | .default) = "${gdbDefaultsTo}"' > \
74 ./package.json
75
76 # Prevent download/install of extensions
77 touch "./install.lock"
78
79 # Mono runtimes from nix package (used by generated `OpenDebugAD7`).
80 mv ./debugAdapters/OpenDebugAD7 ./debugAdapters/OpenDebugAD7_orig
81 cp -p "${openDebugAD7Script}" "./debugAdapters/OpenDebugAD7"
82
83 # Clang-format from nix package.
84 mv ./LLVM/ ./LLVM_orig
85 mkdir "./LLVM/"
86 find "${clang-tools}" -mindepth 1 -maxdepth 1 | xargs ln -s -t "./LLVM"
87
88 # Patching cpptools and cpptools-srv
89 elfInterpreter="$(cat $NIX_CC/nix-support/dynamic-linker)"
90 patchelf --set-interpreter "$elfInterpreter" ./bin/cpptools
91 patchelf --set-interpreter "$elfInterpreter" ./bin/cpptools-srv
92 chmod a+x ./bin/cpptools{-srv,}
93 '';
94
95 meta = with stdenv.lib; {
96 license = licenses.unfree;
97 maintainers = [ maintainers.jraygauthier ];
98 # A 32 bit linux would also be possible with some effort (specific download of binaries +
99 # patching of the elf files with 32 bit interpreter).
100 platforms = [ "x86_64-linux" ];
101 };
102}