···22, vscodeExtensions ? [] }:
3344/*
55- `vsixExtensions`
55+ `vscodeExtensions`
66 : A set of vscode extensions to be installed alongside the editor. Here's a an
77 example:
88···1010 vscode-with-extensions.override {
11111212 # When the extension is already available in the default extensions set.
1313- vscodeExtensions = with vscodeExtensions; [
1414- nix
1313+ vscodeExtensions = with vscode-extensions; [
1414+ bbenoist.Nix
1515 ]
16161717 # Concise version from the vscode market place when not available in the default set.
1818- ++ vscodeUtils.extensionsFromVscodeMarketplace [
1818+ ++ vscode-utils.extensionsFromVscodeMarketplace [
1919 {
2020 name = "code-runner";
2121 publisher = "formulahendry";
+12-5
pkgs/misc/vscode-extensions/default.nix
···33let
44 inherit (vscode-utils) buildVscodeExtension buildVscodeMarketplaceExtension;
55in
66-66+#
77+# Unless there is a good reason not to, we attemp to use the same name as the
88+# extension's unique identifier (the name the extension gets when installed
99+# from vscode under `~/.vscode`) and found on the marketplace extension page.
1010+# So an extension's attribute name should be of the form:
1111+# "${mktplcRef.publisher}.${mktplcRef.name}".
1212+#
713rec {
88- nix = buildVscodeMarketplaceExtension {
1414+ bbenoist.Nix = buildVscodeMarketplaceExtension {
915 mktplcRef = {
1010- name = "nix";
1616+ name = "Nix";
1117 publisher = "bbenoist";
1218 version = "1.0.1";
1319 sha256 = "0zd0n9f5z1f0ckzfjr38xw2zzmcxg1gjrava7yahg5cvdcw6l35b";
1420 };
1515-1616- # TODO: Fill meta with appropriate information.
2121+ meta = with stdenv.lib; {
2222+ license = licenses.mit;
2323+ };
1724 };
1825}
+14-25
pkgs/misc/vscode-extensions/vscode-utils.nix
···11-{ stdenv, lib, fetchurl, runCommand, vscode, which }:
11+{ stdenv, lib, fetchurl, runCommand, vscode, unzip }:
2233let
44 extendedPkgVersion = lib.getVersion vscode;
···77 mktplcExtRefToFetchArgs = ext: {
88 url = "https://${ext.publisher}.gallery.vsassets.io/_apis/public/gallery/publisher/${ext.publisher}/extension/${ext.name}/${ext.version}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage";
99 sha256 = ext.sha256;
1010- name = "${ext.name}.vsix";
1010+ # The `*.vsix` file is in the end a simple zip file. Change the extension
1111+ # so that existing `unzip` hooks takes care of the unpacking.
1212+ name = "${ext.publisher}-${ext.name}.zip";
1113 };
12141315 buildVscodeExtension = a@{
1416 name,
1517 namePrefix ? "${extendedPkgName}-extension-",
1618 src,
1919+ # Same as "Unique Identifier" on the extension's web page.
2020+ # For the moment, only serve as unique extension dir.
2121+ vscodeExtUniqueId,
1722 configurePhase ? ":",
1823 buildPhase ? ":",
1924 dontPatchELF ? true,
···2126 buildInputs ? [],
2227 ...
2328 }:
2424- stdenv.mkDerivation (a // {
2929+ stdenv.mkDerivation ((removeAttrs a [ "vscodeExtUniqueId" ]) // {
25302631 name = namePrefix + name;
27323333+ inherit vscodeExtUniqueId;
2834 inherit configurePhase buildPhase dontPatchELF dontStrip;
29353030- # TODO: `which` is an encapsulation leak. It should have been hardwired
3131- # as part of the `code` wrapper.
3232- buildInputs = [ vscode which ] ++ buildInputs;
3333-3434- unpackPhase = ''
3535- # TODO: Unfortunately, 'code' systematically creates its '.vscode' directory
3636- # even tough it has nothing to write in it. We need to redirect this
3737- # to a writeable location as the nix environment already has (but
3838- # to a non writeable one) otherwise the write will fail.
3939- # It would be preferrable if we could intercept / fix this at the source.
4040- HOME="$PWD/code_null_home" code \
4141- --extensions-dir "$PWD" \
4242- --install-extension "${toString src}"
4343-4444- rm -Rf "$PWD/code_null_home"
4545- cd "$(find . -mindepth 1 -type d -print -quit)"
4646- ls -la
4747- '';
4848-3636+ buildInputs = [ unzip ] ++ buildInputs;
49375038 installPhase = ''
5151- mkdir -p "$out/share/${extendedPkgName}/extensions/${name}"
5252- find . -mindepth 1 -maxdepth 1 | xargs mv -t "$out/share/${extendedPkgName}/extensions/${name}/"
3939+ mkdir -p "$out/share/${extendedPkgName}/extensions/${vscodeExtUniqueId}"
4040+ find . -mindepth 1 -maxdepth 1 | xargs mv -t "$out/share/${extendedPkgName}/extensions/${vscodeExtUniqueId}/"
5341 '';
54425543 });
···6553 ...
6654 }: assert "" == name; assert null == src;
6755 buildVscodeExtension ((removeAttrs a [ "mktplcRef" ]) // {
6868- name = "${mktplcRef.name}-${mktplcRef.version}";
5656+ name = "${mktplcRef.publisher}-${mktplcRef.name}-${mktplcRef.version}";
6957 src = fetchVsixFromVscodeMarketplace mktplcRef;
5858+ vscodeExtUniqueId = "${mktplcRef.publisher}.${mktplcRef.name}";
7059 });
71607261 mktplcRefAttrList = [