@@ -0,0 +1,138 @@
1+# Baseed on previous attempts:
2+# - <https://github.com/msteen/nixos-vsliveshare/blob/master/pkgs/vsliveshare/default.nix>
3+# - <https://github.com/NixOS/nixpkgs/issues/41189>
4+{ lib, gccStdenv, vscode-utils, autoPatchelfHook, bash, file, makeWrapper, dotnet-sdk_3
5+, curl, gcc, icu, libkrb5, libsecret, libunwind, libX11, lttng-ust, openssl, utillinux, zlib
6+, desktop-file-utils, xprop
7+}:
8+
9+with lib;
10+
11+let
12+ # https://docs.microsoft.com/en-us/visualstudio/liveshare/reference/linux#install-prerequisites-manually
13+ libs = [
14+ # .NET Core
15+ openssl
16+ libkrb5
17+ zlib
18+ icu
19+
20+ # Credential Storage
21+ libsecret
22+
23+ # NodeJS
24+ libX11
25+
26+ # https://github.com/flathub/com.visualstudio.code.oss/issues/11#issuecomment-392709170
27+ libunwind
28+ lttng-ust
29+ curl
30+
31+ # General
32+ gcc.cc.lib
33+ utillinux # libuuid
34+ ];
35+
36+in ((vscode-utils.override { stdenv = gccStdenv; }).buildVscodeMarketplaceExtension {
37+ mktplcRef = {
38+ name = "vsliveshare";
39+ publisher = "ms-vsliveshare";
40+ version = "1.0.2902";
41+ sha256 = "0fx2vi0wxamcwqcgcx7wpg8hi7f1c2pibrmd2qy2whilpsv3gzmb";
42+ };
43+}).overrideAttrs(attrs: {
44+ buildInputs = attrs.buildInputs ++ libs ++ [ autoPatchelfHook bash file makeWrapper ];
45+
46+ # Using a patch file won't work, because the file changes too often, causing the patch to fail on most updates.
47+ # Rather than patching the calls to functions, we modify the functions to return what we want,
48+ # which is less likely to break in the future.
49+ postPatch = ''
50+ sed -i \
51+ -e 's/updateExecutablePermissionsAsync() {/& return;/' \
52+ -e 's/isInstallCorrupt(traceSource, manifest) {/& return false;/' \
53+ out/prod/extension-prod.js
54+
55+ declare ext_unique_id
56+ ext_unique_id="$(basename "$out")"
57+
58+ # Fix extension attempting to write to 'modifiedInternalSettings.json'.
59+ # Move this write to the tmp directory indexed by the nix store basename.
60+ sed -i \
61+ -E -e $'s/path\.resolve\(constants_1\.EXTENSION_ROOT_PATH, \'\.\/modifiedInternalSettings\.json\'\)/path.join\(os.tmpdir(), "'$ext_unique_id'" + "-modifiedInternalSettings.json"\)/g' \
62+ out/prod/extension-prod.js
63+
64+ # Fix extension attempting to write to 'vsls-agent.lock'.
65+ # Move this write to the tmp directory indexed by the nix store basename.
66+ sed -i \
67+ -E -e $'s/(Agent_1.getAgentPath\(\) \+ \'.lock\')/path.join\(os.tmpdir(), "'$ext_unique_id'" + "-vsls-agent.lock"\)/g' \
68+ out/prod/extension-prod.js
69+
70+ # TODO: Under 'node_modules/@vsliveshare/vscode-launcher-linux' need to hardcode path to 'desktop-file-install'
71+ # 'update-desktop-database' and 'xprop'. Might want to wrap the script instead.
72+ '';
73+
74+ # Support for the `postInstall` hook was added only in nixos-20.03,
75+ # so for backwards compatibility reasons lets not use it yet.
76+ installPhase = attrs.installPhase + ''
77+ # Support both the new and old directory structure of vscode extensions.
78+ if [[ -d $out/ms-vsliveshare.vsliveshare ]]; then
79+ cd $out/ms-vsliveshare.vsliveshare
80+ elif [[ -d $out/share/vscode/extensions/ms-vsliveshare.vsliveshare ]]; then
81+ cd $out/share/vscode/extensions/ms-vsliveshare.vsliveshare
82+ else
83+ echo "Could not find extension directory 'ms-vsliveshare.vsliveshare'." >&2
84+ exit 1
85+ fi
86+
87+ bash -s <<ENDSUBSHELL
88+ shopt -s extglob
89+
90+ # A workaround to prevent the journal filling up due to diagnostic logging.
91+ # See: https://github.com/MicrosoftDocs/live-share/issues/1272
92+ # See: https://unix.stackexchange.com/questions/481799/how-to-prevent-a-process-from-writing-to-the-systemd-journal
93+ gcc -fPIC -shared -ldl -o dotnet_modules/noop-syslog.so ${./noop-syslog.c}
94+
95+ # Normally the copying of the right executables is done externally at a later time,
96+ # but we want it done at installation time.
97+ cp dotnet_modules/exes/linux-x64/* dotnet_modules
98+
99+ # The required executables are already copied over,
100+ # and the other runtimes won't be used and thus are just a waste of space.
101+ rm -r dotnet_modules/exes dotnet_modules/runtimes/!(linux-x64)
102+
103+ # Not all executables and libraries are executable, so make sure that they are.
104+ find . -type f ! -executable -exec file {} + | grep -w ELF | cut -d ':' -f1 | xargs -rd'\n' chmod +x
105+
106+ # Not all scripts are executed by passing them to a shell, so they need to be executable as well.
107+ find . -type f -name '*.sh' ! -executable -exec chmod +x {} +
108+
109+ # Lock the extension downloader.
110+ touch install-linux.Lock externalDeps-linux.Lock
111+ ENDSUBSHELL
112+ '';
113+
114+ rpath = makeLibraryPath libs;
115+
116+ postFixup = ''
117+ # We cannot use `wrapProgram`, because it will generate a relative path,
118+ # which will break when copying over the files.
119+ mv dotnet_modules/vsls-agent{,-wrapped}
120+ makeWrapper $PWD/dotnet_modules/vsls-agent{-wrapped,} \
121+ --prefix LD_LIBRARY_PATH : "$rpath" \
122+ --set LD_PRELOAD $PWD/dotnet_modules/noop-syslog.so \
123+ --set DOTNET_ROOT ${dotnet-sdk_3}
124+
125+ for bn in check-reqs.sh install.sh uninstall.sh; do
126+ wrapProgram "$PWD/node_modules/@vsliveshare/vscode-launcher-linux/$bn" \
127+ --prefix PATH : "${makeBinPath [desktop-file-utils xprop]}"
128+ done
129+ '';
130+
131+ meta = {
132+ description = "Live Share lets you achieve greater confidence at speed by streamlining collaborative editing, debugging, and more in real-time during development";
133+ homepage = "https://aka.ms/vsls-docs";
134+ license = licenses.unfree;
135+ maintainers = with maintainers; [ jraygauthier ];
136+ platforms = [ "x86_64-linux" ];
137+ };
138+})