diff options
Diffstat (limited to 'nixpkgs/pkgs/misc/vscode-extensions')
24 files changed, 1442 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/misc/vscode-extensions/cpptools/default.nix b/nixpkgs/pkgs/misc/vscode-extensions/cpptools/default.nix new file mode 100644 index 000000000000..8c46b242ef45 --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/cpptools/default.nix @@ -0,0 +1,102 @@ +{ stdenv, vscode-utils +, fetchurl, unzip +, mono, writeScript, runtimeShell +, jq, clang-tools +, gdbUseFixed ? true, gdb # The gdb default setting will be fixed to specified. Use version from `PATH` otherwise. +}: + +assert gdbUseFixed -> null != gdb; + +/* + Note that this version of the extension still has some nix specific issues + which could not be fixed merely by patching (inside a C# dll). + + In particular, the debugger requires either gnome-terminal or xterm. However + instead of looking for the terminal executable in `PATH`, for any linux platform + the dll uses an hardcoded path to one of these. + + So, in order for debugging to work properly, you merely need to create symlinks + to one of these terminals at the appropriate location. + + The good news is the the utility library is open source and with some effort + we could build a patched version ourselves. See: + + <https://github.com/Microsoft/MIEngine/blob/2885386dc7f35e0f1e44827269341e786361f28e/src/MICore/TerminalLauncher.cs#L156> + + Also, the extension should eventually no longer require an external terminal. See: + + <https://github.com/Microsoft/vscode-cpptools/issues/35> + + Once the symbolic link temporary solution taken, everything shoud run smootly. +*/ + +let + gdbDefaultsTo = if gdbUseFixed then "${gdb}/bin/gdb" else "gdb"; + + + openDebugAD7Script = writeScript "OpenDebugAD7" '' + #!${runtimeShell} + BIN_DIR="$(cd "$(dirname "$0")" && pwd -P)" + ${if gdbUseFixed + then '' + export PATH=''${PATH}''${PATH:+:}${gdb}/bin + '' + else ""} + ${mono}/bin/mono $BIN_DIR/bin/OpenDebugAD7.exe $* + ''; +in + +vscode-utils.buildVscodeMarketplaceExtension rec { + mktplcRef = { + name = "cpptools"; + publisher = "ms-vscode"; + version = "0.29.0"; + }; + + vsix = fetchurl { + name = "${mktplcRef.publisher}-${mktplcRef.name}.zip"; + url = "https://github.com/microsoft/vscode-cpptools/releases/download/${mktplcRef.version}/cpptools-linux.vsix"; + sha256 = "0qw21wd6hfqrmvyvr2ggydcfsk1hralj5x3s8hhwqyspb7szggxi"; + }; + + buildInputs = [ + jq + ]; + + postPatch = '' + mv ./package.json ./package_orig.json + + # 1. Add activation events so that the extension is functional. This listing is empty when unpacking the extension but is filled at runtime. + # 2. Patch `package.json` so that nix's *gdb* is used as default value for `miDebuggerPath`. + cat ./package_orig.json | \ + jq --slurpfile actEvts ${./package-activation-events.json} '(.activationEvents) = $actEvts[0]' | \ + jq '(.contributes.debuggers[].configurationAttributes | .attach , .launch | .properties.miDebuggerPath | select(. != null) | select(.default == "/usr/bin/gdb") | .default) = "${gdbDefaultsTo}"' > \ + ./package.json + + # Prevent download/install of extensions + touch "./install.lock" + + # Mono runtimes from nix package (used by generated `OpenDebugAD7`). + mv ./debugAdapters/OpenDebugAD7 ./debugAdapters/OpenDebugAD7_orig + cp -p "${openDebugAD7Script}" "./debugAdapters/OpenDebugAD7" + + # Clang-format from nix package. + mv ./LLVM/ ./LLVM_orig + mkdir "./LLVM/" + find "${clang-tools}" -mindepth 1 -maxdepth 1 | xargs ln -s -t "./LLVM" + + # Patching cpptools and cpptools-srv + elfInterpreter="$(cat $NIX_CC/nix-support/dynamic-linker)" + patchelf --set-interpreter "$elfInterpreter" ./bin/cpptools + patchelf --set-interpreter "$elfInterpreter" ./bin/cpptools-srv + chmod a+x ./bin/cpptools{-srv,} + ''; + + meta = with stdenv.lib; { + license = licenses.unfree; + maintainers = [ maintainers.jraygauthier ]; + # A 32 bit linux would also be possible with some effort (specific download of binaries + + # patching of the elf files with 32 bit interpreter). + platforms = [ "x86_64-linux" ]; + }; +} diff --git a/nixpkgs/pkgs/misc/vscode-extensions/cpptools/missing_elf_deps.sh b/nixpkgs/pkgs/misc/vscode-extensions/cpptools/missing_elf_deps.sh new file mode 100755 index 000000000000..f5eb08d78a5d --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/cpptools/missing_elf_deps.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env nix-shell +#! nix-shell -p coreutils -i bash + +scriptDir=$(cd "`dirname "$0"`"; pwd) +echo "scriptDir='$scriptDir'" + +function get_pkg_out() { + local pkg="$1" + local suffix="${2:-}" + local nixExp="with (import <nixpkgs> {}); ${pkg}" + echo "$(nix-build -E "$nixExp" --no-out-link)${suffix}" +} + +interpreter="$(get_pkg_out "stdenv.glibc" "/lib/ld-linux-x86-64.so.2")" +echo "interpreter='$interpreter'" + +# For clangformat dep on 'libtinfo.so.5'. +ncursesLibDir="$(get_pkg_out "ncurses5.out" "/lib")" +echo "ncursesLibDir='$ncursesLibDir'" + +# For clanformat dep on 'libstdc++.so.6'. +stdcppLibDir="$(get_pkg_out "stdenv.cc.cc.lib" "/lib")" +echo "stdcppLibDir='$stdcppLibDir'" + +# For clangformat dep on 'libz.so.1'. +zlibLibDir="$(get_pkg_out "zlib.out" "/lib")" +echo "zlibLibDir='$zlibLibDir'" + +function patchelf_mono() { + local exe="$1" + patchelf --set-interpreter "$interpreter" "$exe" +} + +function patchelf_clangformat() { + local exe="$1" + patchelf --set-interpreter "$interpreter" "$exe" + local rpath="$ncursesLibDir:$stdcppLibDir:$zlibLibDir" + patchelf --set-rpath "$rpath" "$exe" +} + +function print_nix_version_clangtools() { + nixClangToolsBin="$(get_pkg_out "clang-tools" "/bin")" + echo "nixClangToolsBin='$nixClangToolsBin'" + $nixClangToolsBin/clang-format --version +} + +function print_nix_version_mono() { + nixMonoBin="$(get_pkg_out "mono" "/bin")" + echo "nixMonoBin='$nixMonoBin'" + $nixMonoBin/mono --version +} + diff --git a/nixpkgs/pkgs/misc/vscode-extensions/cpptools/package-activation-events.json b/nixpkgs/pkgs/misc/vscode-extensions/cpptools/package-activation-events.json new file mode 100644 index 000000000000..c2d8a10f340a --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/cpptools/package-activation-events.json @@ -0,0 +1,25 @@ +[ + "onLanguage:cpp", + "onLanguage:c", + "onCommand:extension.pickNativeProcess", + "onCommand:extension.pickRemoteNativeProcess", + "onCommand:C_Cpp.ConfigurationEdit", + "onCommand:C_Cpp.ConfigurationSelect", + "onCommand:C_Cpp.ConfigurationProviderSelect", + "onCommand:C_Cpp.SwitchHeaderSource", + "onCommand:C_Cpp.Navigate", + "onCommand:C_Cpp.GoToDeclaration", + "onCommand:C_Cpp.PeekDeclaration", + "onCommand:C_Cpp.ToggleErrorSquiggles", + "onCommand:C_Cpp.ToggleIncludeFallback", + "onCommand:C_Cpp.ToggleDimInactiveRegions", + "onCommand:C_Cpp.ToggleSnippets", + "onCommand:C_Cpp.ShowReleaseNotes", + "onCommand:C_Cpp.ResetDatabase", + "onCommand:C_Cpp.PauseParsing", + "onCommand:C_Cpp.ResumeParsing", + "onCommand:C_Cpp.ShowParsingCommands", + "onCommand:C_Cpp.TakeSurvey", + "onDebug", + "workspaceContains:/.vscode/c_cpp_properties.json" +] diff --git a/nixpkgs/pkgs/misc/vscode-extensions/cpptools/update_helper.sh b/nixpkgs/pkgs/misc/vscode-extensions/cpptools/update_helper.sh new file mode 100755 index 000000000000..00ef77553242 --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/cpptools/update_helper.sh @@ -0,0 +1,168 @@ +#!/usr/bin/env nix-shell +#! nix-shell -p coreutils -p jq -p unzip -i bash +set -euo pipefail + +# +# A little script to help maintaining this package. It will: +# +# - download the specified version of the extension to the store and print its url, packed store path and hash +# - unpack the extension, bring it to the store and print its store path and hash +# - fetch its runtimes dependencies from the 'package.json' file using the 'jq' utility, unpack those to the store +# and print its url store path and hash +# - patch elf of the binaries that got a nix replacement +# - bring the patched version to the store +# - run their '--version' and call 'ldd' +# - print the version of the runtime deps nix replacements. +# +# TODO: Print to a properly formated nix file all the required information to fetch everything (extension + runtime deps). +# TODO: Print x86 and maybe darwin runtime dependencies. +# + +scriptDir=$(cd "`dirname "$0"`"; pwd) +echo "scriptDir='$scriptDir'" + +extPublisher="vscode" +extName="cpptools" +defaultExtVersion="0.16.1" +extVersion="${1:-$defaultExtVersion}" + +echo +echo "------------- Downloading extension ---------------" + +extZipStoreName="${extPublisher}-${extName}.zip" +extUrl="https://ms-vscode.gallery.vsassets.io/_apis/public/gallery/publisher/ms-vscode/extension/cpptools/${extVersion}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage" +echo "extUrl='$extUrl'" +storePathWithSha=$(nix-prefetch-url --name "$extZipStoreName" --print-path "$extUrl" 2> /dev/null) + +cpptoolsZipStorePath="$(echo "$storePathWithSha" | tail -n1)" +cpptoolsZipSha256="$(echo "$storePathWithSha" | head -n1)" +echo "cpptoolsZipStorePath='$cpptoolsZipStorePath'" +echo "cpptoolsZipSha256='$cpptoolsZipSha256'" + + +extStoreName="${extPublisher}-${extName}" + + +function rm_tmpdir() { + #echo "Removing \`tmpDir='$tmpDir'\`" + rm -rf -- "$tmpDir" + unset tmpDir + trap - INT TERM HUP EXIT +} +function make_trapped_tmpdir() { + tmpDir=$(mktemp -d) + trap rm_tmpdir INT TERM HUP EXIT +} + +echo +echo "------------- Unpacked extension ---------------" + +make_trapped_tmpdir +unzip -q -d "$tmpDir" "$cpptoolsZipStorePath" + +cpptoolsStorePath="$(nix add-to-store -n "$extStoreName" "$tmpDir")" +cpptoolsSha256="$(nix hash-path --base32 --type sha512 "$cpptoolsStorePath")" +echo "cpptoolsStorePath='$cpptoolsStorePath'" +echo "cpptoolsSha256='$cpptoolsSha256'" + +rm_tmpdir + +storePathWithSha=$(nix-prefetch-url --print-path "file://${cpptoolsStorePath}/extension/package.json" 2> /dev/null) + +extPackageJSONStorePath="$(echo "$storePathWithSha" | tail -n1)" +extPackageJSONSha256="$(echo "$storePathWithSha" | head -n1)" +echo "extPackageJSONStorePath='$extPackageJSONStorePath'" +echo "extPackageJSONSha256='$extPackageJSONSha256'" + +print_runtime_dep() { + + local outName="$1" + local extPackageJSONStorePath="$2" + local depDesc="$3" + + local urlRaw=$(cat "$extPackageJSONStorePath" | jq -r --arg desc "$depDesc" '.runtimeDependencies[] | select(.description == $desc) | .url') + local url=$(echo $urlRaw | xargs curl -Ls -o /dev/null -w %{url_effective}) + + local urlRawVarStr="${outName}_urlRaw='$urlRaw'" + local urlVarStr="${outName}_url='$url'" + echo "$urlRawVarStr" + echo "$urlVarStr" + + local storePathWithSha="$(nix-prefetch-url --unpack --print-path "$url" 2> /dev/null)" + + local storePath="$(echo "$storePathWithSha" | tail -n1)" + local sha256="$(echo "$storePathWithSha" | head -n1)" + + local sha256VarStr="${outName}_sha256='$sha256'" + local storePathVarStr="${outName}_storePath='$storePath'" + echo "$sha256VarStr" + echo "$storePathVarStr" + + eval "$urlRawVarStr" + eval "$urlVarStr" + eval "$sha256VarStr" + eval "$storePathVarStr" +} + +echo +echo "------------- Runtime dependencies ---------------" + +print_runtime_dep "langComponentBinaries" "$extPackageJSONStorePath" "C/C++ language components (Linux / x86_64)" +print_runtime_dep "monoRuntimeBinaries" "$extPackageJSONStorePath" "Mono Runtime (Linux / x86_64)" +print_runtime_dep "clanFormatBinaries" "$extPackageJSONStorePath" "ClangFormat (Linux / x86_64)" + + +echo +echo "------------- Runtime deps missing elf deps ---------------" + +source "$scriptDir/missing_elf_deps.sh" + +echo +echo "------------- Runtime dep mono ---------------" + +make_trapped_tmpdir +find "$monoRuntimeBinaries_storePath" -mindepth 1 -maxdepth 1 | xargs -d '\n' cp -rp -t "$tmpDir" +chmod -R a+rwx "$tmpDir" + +ls -la "$tmpDir/debugAdapters" + +patchelf_mono "$tmpDir/debugAdapters/mono.linux-x86_64" + +chmod a+x "$tmpDir/debugAdapters/mono.linux-x86_64" +ldd "$tmpDir/debugAdapters/mono.linux-x86_64" +"$tmpDir/debugAdapters/mono.linux-x86_64" --version + +monoRuntimeBinariesPatched_storePath="$(nix add-to-store -n "monoRuntimeBinariesPatched" "$tmpDir")" +echo "monoRuntimeBinariesPatched_storePath='$monoRuntimeBinariesPatched_storePath'" + +rm_tmpdir + + +echo +echo "------------- Runtime dep clang ---------------" +make_trapped_tmpdir +find "$clanFormatBinaries_storePath" -mindepth 1 -maxdepth 1 | xargs -d '\n' cp -rp -t "$tmpDir" +chmod -R a+rwx "$tmpDir" + +ls -la "$tmpDir/bin" + +patchelf_clangformat "$tmpDir/bin/clang-format" + +chmod a+x "$tmpDir/bin/clang-format" +ldd "$tmpDir/bin/clang-format" +"$tmpDir/bin/clang-format" --version + + +clanFormatBinariesPatched_storePath="$(nix add-to-store -n "clanFormatBinariesPatched" "$tmpDir")" +echo "clanFormatBinariesPatched_storePath='$clanFormatBinariesPatched_storePath'" + +rm_tmpdir + +echo +echo "------------- Nix mono ---------------" +print_nix_version_clangtools + +echo +echo "------------- Nix mono ---------------" +print_nix_version_mono + diff --git a/nixpkgs/pkgs/misc/vscode-extensions/default.nix b/nixpkgs/pkgs/misc/vscode-extensions/default.nix new file mode 100644 index 000000000000..a914d70f173e --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/default.nix @@ -0,0 +1,225 @@ +{ stdenv, callPackage, vscode-utils, llvmPackages_8, llvmPackages_latest }: + +let + inherit (vscode-utils) buildVscodeMarketplaceExtension; +in +# +# Unless there is a good reason not to, we attempt to use the same name as the +# extension's unique identifier (the name the extension gets when installed +# from vscode under `~/.vscode`) and found on the marketplace extension page. +# So an extension's attribute name should be of the form: +# "${mktplcRef.publisher}.${mktplcRef.name}". +# +{ + + alanz.vscode-hie-server = buildVscodeMarketplaceExtension { + mktplcRef = { + name = "vscode-hie-server"; + publisher = "alanz"; + version = "0.0.27"; # see the note above + sha256 = "1mz0h5zd295i73hbji9ivla8hx02i4yhqcv6l4r23w3f07ql3i8h"; + }; + meta = { + license = stdenv.lib.licenses.mit; + }; + }; + + bbenoist.Nix = buildVscodeMarketplaceExtension { + mktplcRef = { + name = "Nix"; + publisher = "bbenoist"; + version = "1.0.1"; + sha256 = "0zd0n9f5z1f0ckzfjr38xw2zzmcxg1gjrava7yahg5cvdcw6l35b"; + }; + meta = with stdenv.lib; { + license = licenses.mit; + }; + }; + + cmschuetz12.wal = buildVscodeMarketplaceExtension { + mktplcRef = { + name = "wal"; + publisher = "cmschuetz12"; + version = "0.1.0"; + sha256 = "0q089jnzqzhjfnv0vlb5kf747s3mgz64r7q3zscl66zb2pz5q4zd"; + }; + meta = with stdenv.lib; { + license = licenses.mit; + }; + }; + + formulahendry.auto-close-tag = buildVscodeMarketplaceExtension { + mktplcRef = { + name = "auto-close-tag"; + publisher = "formulahendry"; + version = "0.5.6"; + sha256 = "058jgmllqb0j6gg5anghdp35nkykii28igfcwqgh4bp10pyvspg0"; + }; + meta = { + license = stdenv.lib.licenses.mit; + }; + }; + + haskell.haskell = buildVscodeMarketplaceExtension { + mktplcRef = { + name = "haskell"; + publisher = "haskell"; + version = "1.1.0"; + sha256 = "1wg06lyk0qn9jd6gi007sg7v0z9z8gwq7x2449d4ihs9n3w5l0gb"; + }; + meta = with stdenv.lib; { + license = licenses.mit; + }; + }; + + james-yu.latex-workshop = buildVscodeMarketplaceExtension { + mktplcRef = { + name = "latex-workshop"; + publisher = "James-Yu"; + version = "8.2.0"; + sha256 = "1ai16aam4v5jzhxgms589q0l24kyk1a9in6z4i7g05b3sahyxab2"; + }; + meta = with stdenv.lib; { + license = licenses.mit; + }; + }; + + justusadam.language-haskell = buildVscodeMarketplaceExtension { + mktplcRef = { + name = "language-haskell"; + publisher = "justusadam"; + version = "3.2.1"; + sha256 = "0lxp8xz17ciy93nj4lzxqvz71vw1zdyamrnh2n792yair8890rr6"; + }; + meta = { + license = stdenv.lib.licenses.bsd3; + }; + }; + + ms-azuretools.vscode-docker = buildVscodeMarketplaceExtension { + mktplcRef = { + name = "vscode-docker"; + publisher = "ms-azuretools"; + version = "0.8.1"; + sha256 = "0n59whmcrx8946xix6skvc50f2vsc85ckvn8cs06w9mqmymm1q0s"; + }; + meta = { + license = stdenv.lib.licenses.mit; + }; + }; + + ms-kubernetes-tools.vscode-kubernetes-tools = buildVscodeMarketplaceExtension { + mktplcRef = { + name = "vscode-kubernetes-tools"; + publisher = "ms-kubernetes-tools"; + version = "1.0.6"; + sha256 = "12a4phl1pddsajy3n0ld6rp607iy0pif6pqrs6ljbg2x97fyra28"; + }; + meta = { + license = stdenv.lib.licenses.mit; + }; + }; + + ms-vscode.Go = buildVscodeMarketplaceExtension { + mktplcRef = { + name = "Go"; + publisher = "ms-vscode"; + version = "0.11.7"; + sha256 = "1l6jjdfivw1pn9y4d4i7zf80ls1k1b0ap1d828ah57ad3bgmyqfi"; + }; + meta = { + license = stdenv.lib.licenses.mit; + }; + }; + + ms-vscode.cpptools = callPackage ./cpptools {}; + + ms-vscode-remote.remote-ssh = callPackage ./remote-ssh {}; + + ms-python.python = callPackage ./python { + extractNuGet = callPackage ./python/extract-nuget.nix { }; + }; + + redhat.vscode-yaml = buildVscodeMarketplaceExtension { + mktplcRef = { + name = "vscode-yaml"; + publisher = "redhat"; + version = "0.5.3"; + sha256 = "03swlsp906rqlrx6jf3ibh7pk36sm0zdr8jfy6sr3w5lqjg27gka"; + }; + meta = { + license = stdenv.lib.licenses.mit; + }; + }; + + matklad.rust-analyzer = callPackage ./rust-analyzer {}; + + scala-lang.scala = buildVscodeMarketplaceExtension { + mktplcRef = { + name = "scala"; + publisher = "scala-lang"; + version = "0.3.8"; + sha256 = "17dl10m3ayf57sqgil4mr9fjdm7i8gb5clrs227b768pp2d39ll9"; + }; + meta = { + license = stdenv.lib.licenses.mit; + }; + }; + + scalameta.metals = buildVscodeMarketplaceExtension { + mktplcRef = { + name = "metals"; + publisher = "scalameta"; + version = "1.9.0"; + sha256 = "0p2wbnw98zmjbfiz4mi1mh131s78r01kjnja339lwdigqxg88gi6"; + }; + meta = { + license = stdenv.lib.licenses.asl20; + }; + }; + + skyapps.fish-vscode = buildVscodeMarketplaceExtension { + mktplcRef = { + name = "fish-vscode"; + publisher = "skyapps"; + version = "0.2.1"; + sha256 = "0y1ivymn81ranmir25zk83kdjpjwcqpnc9r3jwfykjd9x0jib2hl"; + }; + meta = with stdenv.lib; { + license = licenses.mit; + }; + }; + + vadimcn.vscode-lldb = callPackage ./vscode-lldb { + lldb = llvmPackages_latest.lldb; + }; + + vscodevim.vim = buildVscodeMarketplaceExtension { + mktplcRef = { + name = "vim"; + publisher = "vscodevim"; + version = "1.11.3"; + sha256 = "1smzsgcrkhghbnpy51gp28kh74l7y4s2m8pfxabb4ffb751254j0"; + }; + meta = { + license = stdenv.lib.licenses.mit; + }; + }; + + xaver.clang-format = buildVscodeMarketplaceExtension { + mktplcRef = { + name = "clang-format"; + publisher = "xaver"; + version = "1.9.0"; + sha256 = "abd0ef9176eff864f278c548c944032b8f4d8ec97d9ac6e7383d60c92e258c2f"; + }; + meta = with stdenv.lib; { + license = licenses.mit; + maintainers = [ maintainers.zeratax ]; + }; + }; + + llvm-org.lldb-vscode = llvmPackages_8.lldb; + + WakaTime.vscode-wakatime = callPackage ./wakatime {}; +} diff --git a/nixpkgs/pkgs/misc/vscode-extensions/mktplcExtRefToFetchArgs.nix b/nixpkgs/pkgs/misc/vscode-extensions/mktplcExtRefToFetchArgs.nix new file mode 100644 index 000000000000..a781250fc18b --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/mktplcExtRefToFetchArgs.nix @@ -0,0 +1,8 @@ +{ publisher, name, version, sha256 ? "" }: +{ + url = "https://${publisher}.gallery.vsassets.io/_apis/public/gallery/publisher/${publisher}/extension/${name}/${version}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage"; + sha256 = sha256; + # The `*.vsix` file is in the end a simple zip file. Change the extension + # so that existing `unzip` hooks takes care of the unpacking. + name = "${publisher}-${name}.zip"; +} diff --git a/nixpkgs/pkgs/misc/vscode-extensions/python/default.nix b/nixpkgs/pkgs/misc/vscode-extensions/python/default.nix new file mode 100644 index 000000000000..f5dbadd689d8 --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/python/default.nix @@ -0,0 +1,93 @@ +{ lib, stdenv, fetchurl, vscode-utils, extractNuGet +, icu, curl, openssl, lttng-ust, autoPatchelfHook +, python3, musl +, pythonUseFixed ? false # When `true`, the python default setting will be fixed to specified. + # Use version from `PATH` for default setting otherwise. + # Defaults to `false` as we expect it to be project specific most of the time. +, ctagsUseFixed ? true, ctags # When `true`, the ctags default setting will be fixed to specified. + # Use version from `PATH` for default setting otherwise. + # Defaults to `true` as usually not defined on a per projet basis. +}: + +assert ctagsUseFixed -> null != ctags; + +let + pythonDefaultsTo = if pythonUseFixed then "${python3}/bin/python" else "python"; + ctagsDefaultsTo = if ctagsUseFixed then "${ctags}/bin/ctags" else "ctags"; + + # The arch tag comes from 'PlatformName' defined here: + # https://github.com/Microsoft/vscode-python/blob/master/src/client/activation/types.ts + arch = + if stdenv.isLinux && stdenv.isx86_64 then "linux-x64" + else if stdenv.isDarwin then "osx-x64" + else throw "Only x86_64 Linux and Darwin are supported."; + + languageServerSha256 = { + linux-x64 = "1pmj5pb4xylx4gdx4zgmisn0si59qx51n2m1bh7clv29q6biw05n"; + osx-x64 = "0ishiy1z9dghj4ryh95vy8rw0v7q4birdga2zdb4a8am31wmp94b"; + }.${arch}; + + # version is languageServerVersion in the package.json + languageServer = extractNuGet rec { + name = "Python-Language-Server"; + version = "0.5.30"; + + src = fetchurl { + url = "https://pvsc.azureedge.net/python-language-server-stable/${name}-${arch}.${version}.nupkg"; + sha256 = languageServerSha256; + }; + }; +in vscode-utils.buildVscodeMarketplaceExtension rec { + mktplcRef = { + name = "python"; + publisher = "ms-python"; + version = "2020.8.103604"; + }; + + vsix = fetchurl { + name = "${mktplcRef.publisher}-${mktplcRef.name}.zip"; + url = "https://github.com/microsoft/vscode-python/releases/download/${mktplcRef.version}/ms-python-release.vsix"; + sha256 = "1gncnhmwjipaf7hzpimwzqdzyqyy4sznkq4qr2mn1ndjl6s1hh58"; + }; + + buildInputs = [ + icu + curl + openssl + lttng-ust + musl + ]; + + nativeBuildInputs = [ + autoPatchelfHook + python3.pkgs.wrapPython + ]; + + pythonPath = with python3.pkgs; [ + setuptools + ]; + + postPatch = '' + # Patch `packages.json` so that nix's *python* is used as default value for `python.pythonPath`. + substituteInPlace "./package.json" \ + --replace "\"default\": \"python\"" "\"default\": \"${pythonDefaultsTo}\"" + + # Patch `packages.json` so that nix's *ctags* is used as default value for `python.workspaceSymbols.ctagsPath`. + substituteInPlace "./package.json" \ + --replace "\"default\": \"ctags\"" "\"default\": \"${ctagsDefaultsTo}\"" + ''; + + postInstall = '' + mkdir -p "$out/$installPrefix/languageServer.${languageServer.version}" + cp -R --no-preserve=ownership ${languageServer}/* "$out/$installPrefix/languageServer.${languageServer.version}" + chmod -R +wx "$out/$installPrefix/languageServer.${languageServer.version}" + + patchPythonScript "$out/$installPrefix/pythonFiles/lib/python/isort/main.py" + ''; + + meta = with lib; { + license = licenses.mit; + platforms = [ "x86_64-linux" ]; + maintainers = [ maintainers.jraygauthier ]; + }; +} diff --git a/nixpkgs/pkgs/misc/vscode-extensions/python/extract-nuget.nix b/nixpkgs/pkgs/misc/vscode-extensions/python/extract-nuget.nix new file mode 100644 index 000000000000..e4d3b6a0ed1b --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/python/extract-nuget.nix @@ -0,0 +1,15 @@ +{ stdenv, unzip }: +{ name, version, src, ... }: + +stdenv.mkDerivation { + inherit name version src; + + buildInputs = [ unzip ]; + dontBuild = true; + unpackPhase = "unzip $src"; + installPhase = '' + mkdir -p "$out" + chmod -R +w . + find . -mindepth 1 -maxdepth 1 | xargs cp -a -t "$out" + ''; +} diff --git a/nixpkgs/pkgs/misc/vscode-extensions/remote-ssh/default.nix b/nixpkgs/pkgs/misc/vscode-extensions/remote-ssh/default.nix new file mode 100644 index 000000000000..e58ea98a606f --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/remote-ssh/default.nix @@ -0,0 +1,55 @@ +{ stdenv +, vscode-utils +, useLocalExtensions ? false}: +# Note that useLocalExtensions requires that vscode-server is not running +# on host. If it is, you'll need to remove ~/.vscode-server, +# and redo the install by running "Connect to host" on client + +let + inherit (vscode-utils) buildVscodeMarketplaceExtension; + + # patch runs on remote machine hence use of which + # links to local node if version is 12 + patch = '' + f="/home/''$USER/.vscode-server/bin/''$COMMIT_ID/node" + localNodePath=''$(which node) + if [ -x "''$localNodePath" ]; then + localNodeVersion=''$(node -v) + if [ "\''${localNodeVersion:1:2}" = "12" ]; then + echo PATCH: replacing ''$f with ''$localNodePath + rm ''$f + ln -s ''$localNodePath ''$f + fi + fi + ${stdenv.lib.optionalString useLocalExtensions '' + # Use local extensions + if [ -d ~/.vscode/extensions ]; then + if ! test -L "~/.vscode-server/extensions"; then + mkdir -p ~/.vscode-server + ln -s ~/.vscode/extensions ~/.vscode-server/ + fi + fi + ''} + ''; +in + buildVscodeMarketplaceExtension { + mktplcRef = { + name = "remote-ssh"; + publisher = "ms-vscode-remote"; + version = "0.50.0"; + sha256 = "01pyd6759p5nkjhjy3iplrl748xblr54l1jphk2g02s1n5ds2qb9"; + }; + + postPatch = '' + substituteInPlace "out/extension.js" \ + --replace "# install extensions" '${patch}' + ''; + + meta = with stdenv.lib; { + description ="Use any remote machine with a SSH server as your development environment."; + license = licenses.unfree; + maintainers = with maintainers; [ + tbenst + ]; + }; + } diff --git a/nixpkgs/pkgs/misc/vscode-extensions/rust-analyzer/build-deps/package.json b/nixpkgs/pkgs/misc/vscode-extensions/rust-analyzer/build-deps/package.json new file mode 100644 index 000000000000..4af15f4619ea --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/rust-analyzer/build-deps/package.json @@ -0,0 +1,26 @@ +{ + "name": "rust-analyzer", + "version": "0.4.0-dev", + "dependencies": { + "node-fetch": "^2.6.1", + "vscode-languageclient": "7.0.0-next.9", + "@rollup/plugin-commonjs": "^13.0.2", + "@rollup/plugin-node-resolve": "^8.4.0", + "@types/glob": "^7.1.3", + "@types/mocha": "^7.0.2", + "@types/node": "~12.7.0", + "@types/node-fetch": "^2.5.7", + "@types/vscode": "^1.47.1", + "@typescript-eslint/eslint-plugin": "^3.10.1", + "@typescript-eslint/parser": "^3.10.1", + "eslint": "^7.8.0", + "glob": "^7.1.6", + "mocha": "^8.1.3", + "rollup": "^2.26.9", + "tslib": "^2.0.1", + "typescript": "^3.9.7", + "typescript-formatter": "^7.2.2", + "vsce": "^1.79.5", + "vscode-test": "^1.4.0" + } +} diff --git a/nixpkgs/pkgs/misc/vscode-extensions/rust-analyzer/default.nix b/nixpkgs/pkgs/misc/vscode-extensions/rust-analyzer/default.nix new file mode 100644 index 000000000000..d19027fa5762 --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/rust-analyzer/default.nix @@ -0,0 +1,49 @@ +# Update script: pkgs/development/tools/rust/rust-analyzer/update.sh +{ lib, stdenv, vscode-utils, jq, rust-analyzer, nodePackages +, setDefaultServerPath ? true +}: + +let + pname = "rust-analyzer"; + publisher = "matklad"; + + # Follow the unstable version of rust-analyzer, since the extension is not stable yet. + inherit (rust-analyzer) version; + + build-deps = nodePackages."rust-analyzer-build-deps-../../misc/vscode-extensions/rust-analyzer/build-deps"; + # FIXME: Making a new derivation to link `node_modules` and run `npm run package` + # will cause a build failure. + vsix = build-deps.override { + src = "${rust-analyzer.src}/editors/code"; + outputs = [ "vsix" "out" ]; + + postInstall = '' + npm run package + mkdir $vsix + cp ${pname}.vsix $vsix/${pname}.zip + ''; + }; + +in vscode-utils.buildVscodeExtension { + inherit version vsix; + name = "${pname}-${version}"; + src = "${vsix}/${pname}.zip"; + vscodeExtUniqueId = "${publisher}.${pname}"; + + nativeBuildInputs = lib.optional setDefaultServerPath jq; + + preInstall = lib.optionalString setDefaultServerPath '' + jq '.contributes.configuration.properties."rust-analyzer.serverPath".default = $s' \ + --arg s "${rust-analyzer}/bin/rust-analyzer" \ + package.json >package.json.new + mv package.json.new package.json + ''; + + meta = with lib; { + description = "An alternative rust language server to the RLS"; + homepage = "https://github.com/rust-analyzer/rust-analyzer"; + license = with licenses; [ mit asl20 ]; + maintainers = with maintainers; [ oxalica ]; + platforms = platforms.all; + }; +} diff --git a/nixpkgs/pkgs/misc/vscode-extensions/updateSettings.nix b/nixpkgs/pkgs/misc/vscode-extensions/updateSettings.nix new file mode 100644 index 000000000000..c7fecf080720 --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/updateSettings.nix @@ -0,0 +1,39 @@ +# Updates the vscode setting file base on a nix expression +# should run from the workspace root. +{ writeShellScriptBin +, lib +, jq +}: +##User Input +{ settings ? {} +# if marked as true will create an empty json file if does not exists +, createIfDoesNotExists ? true +, vscodeSettingsFile ? ".vscode/settings.json" +, userSettingsFolder ? "" +, symlinkFromUserSetting ? false +}: +let + + updateVSCodeSettingsCmd = '' + ( + echo 'updateSettings.nix: Updating ${vscodeSettingsFile}...' + oldSettings=$(cat ${vscodeSettingsFile}) + echo $oldSettings' ${builtins.toJSON settings}' | ${jq}/bin/jq -s add > ${vscodeSettingsFile} + )''; + + createEmptySettingsCmd = ''mkdir -p .vscode && echo "{}" > ${vscodeSettingsFile}''; + fileName = builtins.baseNameOf vscodeSettingsFile; + symlinkFromUserSettingCmd = lib.optionalString symlinkFromUserSetting + '' && mkdir -p "${userSettingsFolder}" && ln -sfv "$(pwd)/${vscodeSettingsFile}" "${userSettingsFolder}/" ''; +in + + writeShellScriptBin ''vscodeNixUpdate-${lib.removeSuffix ".json" (fileName)}'' + (lib.optionalString (settings != {}) + (if createIfDoesNotExists then '' + [ ! -f "${vscodeSettingsFile}" ] && ${createEmptySettingsCmd} + ${updateVSCodeSettingsCmd} ${symlinkFromUserSettingCmd} + '' + else ''[ -f "${vscodeSettingsFile}" ] && ${updateVSCodeSettingsCmd} ${symlinkFromUserSettingCmd} + '' + ) + ) diff --git a/nixpkgs/pkgs/misc/vscode-extensions/updateSettingsTest.nix b/nixpkgs/pkgs/misc/vscode-extensions/updateSettingsTest.nix new file mode 100644 index 000000000000..097b9cad1661 --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/updateSettingsTest.nix @@ -0,0 +1,6 @@ +with import <nixpkgs>{}; +callPackage (import ./updateSettings.nix) {} { + settings = { + a = "fdsdf"; + }; +} diff --git a/nixpkgs/pkgs/misc/vscode-extensions/update_installed_exts.sh b/nixpkgs/pkgs/misc/vscode-extensions/update_installed_exts.sh new file mode 100755 index 000000000000..fdbc14fb2642 --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/update_installed_exts.sh @@ -0,0 +1,74 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p curl jq unzip +set -eu -o pipefail + +# Helper to just fail with a message and non-zero exit code. +function fail() { + echo "$1" >&2 + exit 1 +} + +# Helper to clean up after ourself if we're killed by SIGINT +function clean_up() { + TDIR="${TMPDIR:-/tmp}" + echo "Script killed, cleaning up tmpdirs: $TDIR/vscode_exts_*" >&2 + rm -Rf "$TDIR/vscode_exts_*" +} + +function get_vsixpkg() { + N="$1.$2" + + # Create a tempdir for the extension download + EXTTMP=$(mktemp -d -t vscode_exts_XXXXXXXX) + + URL="https://$1.gallery.vsassets.io/_apis/public/gallery/publisher/$1/extension/$2/latest/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage" + + # Quietly but delicately curl down the file, blowing up at the first sign of trouble. + curl --silent --show-error --fail -X GET -o "$EXTTMP/$N.zip" "$URL" + # Unpack the file we need to stdout then pull out the version + VER=$(jq -r '.version' <(unzip -qc "$EXTTMP/$N.zip" "extension/package.json")) + # Calculate the SHA + SHA=$(nix-hash --flat --base32 --type sha256 "$EXTTMP/$N.zip") + + # Clean up. + rm -Rf "$EXTTMP" + # I don't like 'rm -Rf' lurking in my scripts but this seems appropriate + + cat <<-EOF + { + name = "$2"; + publisher = "$1"; + version = "$VER"; + sha256 = "$SHA"; + } +EOF +} + +# See if can find our code binary somewhere. +if [ $# -ne 0 ]; then + CODE=$1 +else + CODE=$(command -v code) +fi + +if [ -z "$CODE" ]; then + # Not much point continuing. + fail "VSCode executable not found" +fi + +# Try to be a good citizen and clean up after ourselves if we're killed. +trap clean_up SIGINT + +# Begin the printing of the nix expression that will house the list of extensions. +printf '{ extensions = [\n' + +# Note that we are only looking to update extensions that are already installed. +for i in $($CODE --list-extensions) +do + OWNER=$(echo "$i" | cut -d. -f1) + EXT=$(echo "$i" | cut -d. -f2) + + get_vsixpkg "$OWNER" "$EXT" +done +# Close off the nix expression. +printf '];\n}' diff --git a/nixpkgs/pkgs/misc/vscode-extensions/vscode-lldb/build-deps/package.json b/nixpkgs/pkgs/misc/vscode-extensions/vscode-lldb/build-deps/package.json new file mode 100644 index 000000000000..6e73ee446d86 --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/vscode-lldb/build-deps/package.json @@ -0,0 +1,24 @@ +{ + "name": "vscode-lldb", + "version": "1.5.3", + "dependencies": { + "@types/json5": "^0.0.30", + "@types/mocha": "^7.0.1", + "@types/node": "^8.10.50", + "@types/vscode": "^1.31.0", + "@types/yauzl": "^2.9.0", + "json5": "^2.1.0", + "memory-streams": "^0.1.3", + "mocha": "^7.0.1", + "source-map-support": "^0.5.12", + "string-argv": "^0.3.1", + "ts-loader": "^6.2.1", + "typescript": "^3.7.0", + "vsce": "^1.73.0", + "vscode-debugadapter-testsupport": "^1.35.0", + "vscode-debugprotocol": "^1.35.0", + "webpack": "^4.39.1", + "webpack-cli": "^3.3.7", + "yauzl": "^2.10.0" + } +} diff --git a/nixpkgs/pkgs/misc/vscode-extensions/vscode-lldb/cmake-build-extension-only.patch b/nixpkgs/pkgs/misc/vscode-extensions/vscode-lldb/cmake-build-extension-only.patch new file mode 100644 index 000000000000..db62552b913b --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/vscode-lldb/cmake-build-extension-only.patch @@ -0,0 +1,45 @@ +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -9,13 +9,6 @@ include(cmake/CopyFiles.cmake) + set(CMAKE_CXX_STANDARD 11) + set(CMAKE_INSTALL_PREFIX $ENV{HOME}/.vscode/extensions/vscode-lldb CACHE PATH "Install location") + +-set(LLDB_ROOT $ENV{LLDB_ROOT} CACHE PATH "Root of LLDB build directory") +-if (LLDB_ROOT) +- message("Using LLDB from ${LLDB_ROOT}") +-else() +- message(FATAL_ERROR "LLDB_ROOT not set." ) +-endif() +- + # General OS-specific definitions + if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + set(DylibPrefix lib) +@@ -64,8 +57,9 @@ set(UpdateFile ${CMAKE_COMMAND} -E copy_if_different) + + # Adapter + +-add_subdirectory(adapter) +-add_subdirectory(lldb) ++add_custom_target(adapter) ++add_custom_target(lldb) ++add_custom_target(codelldb) + + # Extension package content + +@@ -74,16 +68,6 @@ configure_file(package.json ${CMAKE_CURRENT_BINARY_DIR}/package.json @ONLY) + configure_file(webpack.config.js ${CMAKE_CURRENT_BINARY_DIR}/webpack.config.js @ONLY) + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/package-lock.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + +-# Run 'npm install' +-execute_process( +- COMMAND ${NPM} install +- WORKING_DIRECTORY ${CMAKE_BINARY_DIR} +- RESULT_VARIABLE Result +-) +-if (NOT ${Result} EQUAL 0) +- message(FATAL_ERROR "npm intall failed: ${Result}") +-endif() +- + # Copy it back, so we can commit the lock file. + file(COPY ${CMAKE_CURRENT_BINARY_DIR}/package-lock.json DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}) + \ No newline at end of file diff --git a/nixpkgs/pkgs/misc/vscode-extensions/vscode-lldb/default.nix b/nixpkgs/pkgs/misc/vscode-extensions/vscode-lldb/default.nix new file mode 100644 index 000000000000..f22c9df36a1b --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/vscode-lldb/default.nix @@ -0,0 +1,106 @@ +{ lib, stdenv, vscode-utils, fetchFromGitHub, rustPlatform, makeWrapper, jq +, nodePackages, cmake, nodejs, unzip, python3, lldb, breakpointHook +, setDefaultLldbPath ? true +}: +assert lib.versionAtLeast python3.version "3.5"; +let + publisher = "vadimcn"; + name = "vscode-lldb"; + version = "1.5.3"; + + dylibExt = stdenv.hostPlatform.extensions.sharedLibrary; + + src = fetchFromGitHub { + owner = "vadimcn"; + repo = "vscode-lldb"; + rev = "v${version}"; + sha256 = "1139945j3z0fxc3nlyvd81k0ypymqsj051idrbgbibwshpi86y93"; + fetchSubmodules = true; + }; + + adapter = rustPlatform.buildRustPackage { + pname = "${name}-adapter"; + inherit version src; + + cargoSha256 = "0jl4msf2jcjxddwqkx8fr0c35wg4vwvg5c19mihri1v34i09zc5r"; + + # It will pollute the build environment of `buildRustPackage`. + cargoPatches = [ ./reset-cargo-config.patch ]; + + nativeBuildInputs = [ makeWrapper ]; + + buildAndTestSubdir = "adapter"; + + # Hack: Need a nightly compiler. + RUSTC_BOOTSTRAP = 1; + + # `adapter` expects a special hierarchy to resolve everything well. + postInstall = '' + mkdir -p $out/adapter + mv -t $out/adapter \ + $out/bin/* \ + $out/lib/* \ + ./adapter/*.py \ + ./formatters/*.py + rmdir $out/{bin,lib} + ''; + + postFixup = '' + wrapProgram $out/adapter/codelldb \ + --prefix PATH : "${python3}/bin" \ + --prefix LD_LIBRARY_PATH : "${python3}/lib" + ''; + }; + + build-deps = nodePackages."vscode-lldb-build-deps-../../misc/vscode-extensions/vscode-lldb/build-deps"; + + vsix = stdenv.mkDerivation { + name = "${name}-${version}-vsix"; + inherit src; + + # Only build the extension. We handle `adapter` and `lldb` with nix. + patches = [ ./cmake-build-extension-only.patch ]; + + nativeBuildInputs = [ cmake nodejs unzip breakpointHook ]; + + postConfigure = '' + cp -r ${build-deps}/lib/node_modules/vscode-lldb/{node_modules,package-lock.json} . + ''; + + makeFlags = [ "vsix_bootstrap" ]; + + installPhase = '' + unzip ./codelldb-bootstrap.vsix 'extension/*' -d ./vsix-extracted + mv vsix-extracted/extension $out + + ln -s ${adapter}/adapter $out + # Mark that adapter and lldb are installed. + touch $out/platform.ok + ''; + + dontStrip = true; + dontPatchELF = true; + }; + +in vscode-utils.buildVscodeExtension { + inherit name; + src = vsix; + + nativeBuildInputs = lib.optional setDefaultLldbPath jq; + postUnpack = lib.optionalString setDefaultLldbPath '' + jq '.contributes.configuration.properties."lldb.library".default = $s' \ + --arg s "${lldb}/lib/liblldb.so" \ + $sourceRoot/package.json >$sourceRoot/package.json.new + mv $sourceRoot/package.json.new $sourceRoot/package.json + ''; + + vscodeExtUniqueId = "${publisher}.${name}"; + + meta = with lib; { + description = "A native debugger extension for VSCode based on LLDB"; + homepage = "https://github.com/vadimcn/vscode-lldb"; + license = with licenses; [ mit ]; + maintainers = with maintainers; [ oxalica ]; + platforms = platforms.all; + }; +} diff --git a/nixpkgs/pkgs/misc/vscode-extensions/vscode-lldb/reset-cargo-config.patch b/nixpkgs/pkgs/misc/vscode-extensions/vscode-lldb/reset-cargo-config.patch new file mode 100644 index 000000000000..300f8cd96ef9 --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/vscode-lldb/reset-cargo-config.patch @@ -0,0 +1,11 @@ +--- a/.cargo/config ++++ b/.cargo/config +@@ -1,8 +0,0 @@ +-[build] +-target-dir = "build/target" +- +-[target.armv7-unknown-linux-gnueabihf] +-linker = "arm-linux-gnueabihf-gcc" +- +-[target.aarch64-unknown-linux-gnu] +-linker = "aarch64-linux-gnu-gcc" diff --git a/nixpkgs/pkgs/misc/vscode-extensions/vscode-utils.nix b/nixpkgs/pkgs/misc/vscode-extensions/vscode-utils.nix new file mode 100644 index 000000000000..1de3bce3d0db --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/vscode-utils.nix @@ -0,0 +1,94 @@ +{ stdenv, lib, buildEnv, writeShellScriptBin, fetchurl, vscode, unzip, jq }: +let + buildVscodeExtension = a@{ + name, + src, + # Same as "Unique Identifier" on the extension's web page. + # For the moment, only serve as unique extension dir. + vscodeExtUniqueId, + configurePhase ? ":", + buildPhase ? ":", + dontPatchELF ? true, + dontStrip ? true, + buildInputs ? [], + ... + }: + stdenv.mkDerivation ((removeAttrs a [ "vscodeExtUniqueId" ]) // { + + name = "vscode-extension-${name}"; + + inherit vscodeExtUniqueId; + inherit configurePhase buildPhase dontPatchELF dontStrip; + + installPrefix = "share/vscode/extensions/${vscodeExtUniqueId}"; + + buildInputs = [ unzip ] ++ buildInputs; + + installPhase = '' + + runHook preInstall + + mkdir -p "$out/$installPrefix" + find . -mindepth 1 -maxdepth 1 | xargs -d'\n' mv -t "$out/$installPrefix/" + + runHook postInstall + ''; + + }); + + fetchVsixFromVscodeMarketplace = mktplcExtRef: + fetchurl((import ./mktplcExtRefToFetchArgs.nix mktplcExtRef)); + + buildVscodeMarketplaceExtension = a@{ + name ? "", + src ? null, + vsix ? null, + mktplcRef, + ... + }: assert "" == name; assert null == src; + buildVscodeExtension ((removeAttrs a [ "mktplcRef" "vsix" ]) // { + name = "${mktplcRef.publisher}-${mktplcRef.name}-${mktplcRef.version}"; + src = if (vsix != null) + then vsix + else fetchVsixFromVscodeMarketplace mktplcRef; + vscodeExtUniqueId = "${mktplcRef.publisher}.${mktplcRef.name}"; + }); + + mktplcRefAttrList = [ + "name" + "publisher" + "version" + "sha256" + ]; + + mktplcExtRefToExtDrv = ext: + buildVscodeMarketplaceExtension ((removeAttrs ext mktplcRefAttrList) // { + mktplcRef = ext; + }); + + extensionFromVscodeMarketplace = mktplcExtRefToExtDrv; + extensionsFromVscodeMarketplace = mktplcExtRefList: + builtins.map extensionFromVscodeMarketplace mktplcExtRefList; + + vscodeWithConfiguration = import ./vscodeWithConfiguration.nix { + inherit lib extensionsFromVscodeMarketplace writeShellScriptBin; + vscodeDefault = vscode; + }; + + + vscodeExts2nix = import ./vscodeExts2nix.nix { + inherit lib writeShellScriptBin; + vscodeDefault = vscode; + }; + + vscodeEnv = import ./vscodeEnv.nix { + inherit lib buildEnv writeShellScriptBin extensionsFromVscodeMarketplace jq; + vscodeDefault = vscode; + }; +in +{ + inherit fetchVsixFromVscodeMarketplace buildVscodeExtension + buildVscodeMarketplaceExtension extensionFromVscodeMarketplace + extensionsFromVscodeMarketplace + vscodeWithConfiguration vscodeExts2nix vscodeEnv; +} diff --git a/nixpkgs/pkgs/misc/vscode-extensions/vscodeEnv.nix b/nixpkgs/pkgs/misc/vscode-extensions/vscodeEnv.nix new file mode 100644 index 000000000000..7c58a4bdfb34 --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/vscodeEnv.nix @@ -0,0 +1,86 @@ +#Use vscodeWithConfiguration and vscodeExts2nix to create a vscode executable. When the executable exits, it updates the mutable extension file, which is imported when evaluated by Nix later. +{ lib +, buildEnv +, writeShellScriptBin +, extensionsFromVscodeMarketplace +, vscodeDefault +, jq +}: +##User input +{ vscode ? vscodeDefault +, nixExtensions ? [] +, vscodeExtsFolderName ? ".vscode-exts" +# will add to the command updateSettings (which will run on executing vscode) settings to override in settings.json file +, settings ? {} +, createSettingsIfDoesNotExists ? true +, launch ? {} +, createLaunchIfDoesNotExists ? true +# will add to the command updateKeybindings(which will run on executing vscode) keybindings to override in keybinding.json file +, keybindings ? {} +, createKeybindingsIfDoesNotExists ? true +, user-data-dir ? ''"''${TMP}''${name}"/vscode-data-dir'' +# if file exists will use it and import the extensions in it into this dervation else will use empty extensions list +# this file will be created/updated by vscodeExts2nix when vscode exists +, mutableExtensionsFile +}: +let + mutableExtensionsFilePath = toString mutableExtensionsFile; + mutableExtensions = if builtins.pathExists mutableExtensionsFile + then import mutableExtensionsFilePath else []; + vscodeWithConfiguration = import ./vscodeWithConfiguration.nix { + inherit lib writeShellScriptBin extensionsFromVscodeMarketplace; + vscodeDefault = vscode; + } + { + inherit nixExtensions mutableExtensions vscodeExtsFolderName user-data-dir; + }; + + updateSettings = import ./updateSettings.nix { inherit lib writeShellScriptBin jq; }; + userSettingsFolder = "${ user-data-dir }/User"; + + updateSettingsCmd = updateSettings { + settings = { + "extensions.autoCheckUpdates" = false; + "extensions.autoUpdate" = false; + "update.mode" = "none"; + } // settings; + inherit userSettingsFolder; + createIfDoesNotExists = createSettingsIfDoesNotExists; + symlinkFromUserSetting = (user-data-dir != ""); + }; + + updateLaunchCmd = updateSettings { + settings = launch; + createIfDoesNotExists = createLaunchIfDoesNotExists; + vscodeSettingsFile = ".vscode/launch.json"; + }; + + updateKeybindingsCmd = updateSettings { + settings = keybindings; + createIfDoesNotExists = createKeybindingsIfDoesNotExists; + vscodeSettingsFile = ".vscode/keybindings.json"; + inherit userSettingsFolder; + symlinkFromUserSetting = (user-data-dir != ""); + }; + + vscodeExts2nix = import ./vscodeExts2nix.nix { + inherit lib writeShellScriptBin; + vscodeDefault = vscodeWithConfiguration; + } + { + extensionsToIgnore = nixExtensions; + extensions = mutableExtensions; + }; + code = writeShellScriptBin "code" '' + ${updateSettingsCmd}/bin/vscodeNixUpdate-settings + ${updateLaunchCmd}/bin/vscodeNixUpdate-launch + ${updateKeybindingsCmd}/bin/vscodeNixUpdate-keybindings + ${vscodeWithConfiguration}/bin/code --wait "$@" + echo 'running vscodeExts2nix to update ${mutableExtensionsFilePath}...' + ${vscodeExts2nix}/bin/vscodeExts2nix > ${mutableExtensionsFilePath} + ''; +in +buildEnv { + name = "vscodeEnv"; + paths = [ code vscodeExts2nix updateSettingsCmd updateLaunchCmd updateKeybindingsCmd ]; +} diff --git a/nixpkgs/pkgs/misc/vscode-extensions/vscodeEnvTest.nix b/nixpkgs/pkgs/misc/vscode-extensions/vscodeEnvTest.nix new file mode 100644 index 000000000000..19a9edbf1afe --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/vscodeEnvTest.nix @@ -0,0 +1,11 @@ +with import <nixpkgs>{}; +callPackage (import ./vscodeEnv.nix) { + extensionsFromVscodeMarketplace = vscode-utils.extensionsFromVscodeMarketplace; + vscodeDefault = vscode; +} { + mutableExtensionsFile = ./extensions.nix; + settings = { + a = "fdsdf"; + t = "test"; + }; +} diff --git a/nixpkgs/pkgs/misc/vscode-extensions/vscodeExts2nix.nix b/nixpkgs/pkgs/misc/vscode-extensions/vscodeExts2nix.nix new file mode 100644 index 000000000000..58ad5866c935 --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/vscodeExts2nix.nix @@ -0,0 +1,44 @@ +# based on the passed vscode will stdout a nix expression with the installed vscode extensions +{ lib +, vscodeDefault +, writeShellScriptBin +}: + +##User input +{ vscode ? vscodeDefault +, extensionsToIgnore ? [] +# will use those extensions to get sha256 if still exists when executed. +, extensions ? [] +}: +let + mktplcExtRefToFetchArgs = import ./mktplcExtRefToFetchArgs.nix; +in +writeShellScriptBin "vscodeExts2nix" '' + echo '[' + + for line in $(${vscode}/bin/code --list-extensions --show-versions \ + ${lib.optionalString (extensionsToIgnore != []) '' + | grep -v -i '^\(${lib.concatMapStringsSep "\\|" (e : ''${e.publisher}.${e.name}'') extensionsToIgnore}\)' + ''} + ) ; do + [[ $line =~ ([^.]*)\.([^@]*)@(.*) ]] + name=''${BASH_REMATCH[2]} + publisher=''${BASH_REMATCH[1]} + version=''${BASH_REMATCH[3]} + + extensions="${lib.concatMapStringsSep "." (e : ''${e.publisher}${e.name}@${e.sha256}'') extensions}" + reCurrentExt=$publisher$name"@([^.]*)" + if [[ $extensions =~ $reCurrentExt ]]; then + sha256=''${BASH_REMATCH[1]} + else + sha256=$( + nix-prefetch-url "${(mktplcExtRefToFetchArgs {publisher = ''"$publisher"''; name = ''"$name"''; version = ''"$version"'';}).url}" 2> /dev/null + ) + fi + + echo "{ name = \"''${name}\"; publisher = \"''${publisher}\"; version = \"''${version}\"; sha256 = \"''${sha256}\"; }" + done + + + echo ']' +'' diff --git a/nixpkgs/pkgs/misc/vscode-extensions/vscodeWithConfiguration.nix b/nixpkgs/pkgs/misc/vscode-extensions/vscodeWithConfiguration.nix new file mode 100644 index 000000000000..e20c631f8c03 --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/vscodeWithConfiguration.nix @@ -0,0 +1,54 @@ +# wrapper over vscode to control extensions per project (extensions folder will be created in execution path) +{ lib +, writeShellScriptBin +, extensionsFromVscodeMarketplace +, vscodeDefault +}: +## User input +{ vscode ? vscodeDefault +# extensions to be symlinked into the project's extensions folder +, nixExtensions ? [] +# extensions to be copied into the project's extensions folder +, mutableExtensions ? [] +, vscodeExtsFolderName ? ".vscode-exts" +, user-data-dir ? ''"''${TMP}vscodeWithConfiguration/vscode-data-dir"'' +}: +let + nixExtsDrvs = extensionsFromVscodeMarketplace nixExtensions; + mutExtsDrvs = extensionsFromVscodeMarketplace mutableExtensions; + mutableExtsPaths = lib.forEach mutExtsDrvs ( e: + { + origin = ''${e}/share/vscode/extensions/${e.vscodeExtUniqueId}''; + target = ''${vscodeExtsFolderName}/${e.vscodeExtUniqueId}-${(lib.findSingle (ext: ''${ext.publisher}.${ext.name}'' == e.vscodeExtUniqueId) "" "m" mutableExtensions ).version}''; + } + ); + + #removed not defined extensions + rmExtensions = lib.optionalString (nixExtensions++mutableExtensions != []) '' + find ${vscodeExtsFolderName} -mindepth 1 -maxdepth 1 ${ + lib.concatMapStringsSep " " (e : ''! -iname ${e.publisher}.${e.name} '') nixExtensions + + + lib.concatMapStringsSep " " (e : ''! -iname ${e.publisher}.${e.name}-${e.version} '') mutableExtensions + } -exec rm -rf {} \; + ''; + #copy mutable extension out of the nix store + cpExtensions = '' + ${lib.concatMapStringsSep "\n" (e : ''ln -sfn ${e}/share/vscode/extensions/* ${vscodeExtsFolderName}/'') nixExtsDrvs} + ${lib.concatMapStringsSep "\n" (ePath : '' + if [ ! -d ${ePath.target} ]; then + cp -a ${ePath.origin} ${ePath.target} + chmod -R u+rwx ${ePath.target} + fi + '') mutableExtsPaths} + ''; +in + writeShellScriptBin "code" '' + if ! [[ "$@" =~ "--list-extension" ]]; then + mkdir -p "${vscodeExtsFolderName}" + ${rmExtensions} + ${cpExtensions} + fi + ${vscode}/bin/code --extensions-dir "${vscodeExtsFolderName}" ${ + lib.optionalString (user-data-dir != "") ''--user-data-dir ${user-data-dir }'' + } "$@" + '' diff --git a/nixpkgs/pkgs/misc/vscode-extensions/wakatime/default.nix b/nixpkgs/pkgs/misc/vscode-extensions/wakatime/default.nix new file mode 100644 index 000000000000..30b2f94f1a58 --- /dev/null +++ b/nixpkgs/pkgs/misc/vscode-extensions/wakatime/default.nix @@ -0,0 +1,30 @@ +{ stdenv +, wakatime, vscode-utils }: + +let + inherit (vscode-utils) buildVscodeMarketplaceExtension; +in + buildVscodeMarketplaceExtension { + mktplcRef = { + name = "vscode-wakatime"; + publisher = "WakaTime"; + version = "4.0.0"; + sha256 = "0bwxz8dg00k8frnvkvcngll5yaf9k7z13dg309vmw8xbdgkiyid4"; + }; + + postPatch = '' + mkdir -p wakatime-master + cp -rt wakatime-master --no-preserve=all ${wakatime}/lib/python*/site-packages/wakatime + ''; + + meta = with stdenv.lib; { + description = '' + Visual Studio Code plugin for automatic time tracking and metrics generated + from your programming activity + ''; + license = licenses.bsd3; + maintainers = with maintainers; [ + eadwu + ]; + }; + } |