···2, vscodeExtensions ? [] }:
34/*
5- `vsixExtensions`
6 : A set of vscode extensions to be installed alongside the editor. Here's a an
7 example:
8···10 vscode-with-extensions.override {
1112 # When the extension is already available in the default extensions set.
13- vscodeExtensions = with vscodeExtensions; [
14- nix
15 ]
1617 # Concise version from the vscode market place when not available in the default set.
18- ++ vscodeUtils.extensionsFromVscodeMarketplace [
19 {
20 name = "code-runner";
21 publisher = "formulahendry";
···2, vscodeExtensions ? [] }:
34/*
5+ `vscodeExtensions`
6 : A set of vscode extensions to be installed alongside the editor. Here's a an
7 example:
8···10 vscode-with-extensions.override {
1112 # When the extension is already available in the default extensions set.
13+ vscodeExtensions = with vscode-extensions; [
14+ bbenoist.Nix
15 ]
1617 # Concise version from the vscode market place when not available in the default set.
18+ ++ vscode-utils.extensionsFromVscodeMarketplace [
19 {
20 name = "code-runner";
21 publisher = "formulahendry";
+12-5
pkgs/misc/vscode-extensions/default.nix
···3let
4 inherit (vscode-utils) buildVscodeExtension buildVscodeMarketplaceExtension;
5in
6-0000007rec {
8- nix = buildVscodeMarketplaceExtension {
9 mktplcRef = {
10- name = "nix";
11 publisher = "bbenoist";
12 version = "1.0.1";
13 sha256 = "0zd0n9f5z1f0ckzfjr38xw2zzmcxg1gjrava7yahg5cvdcw6l35b";
14 };
15-16- # TODO: Fill meta with appropriate information.
017 };
18}
···3let
4 inherit (vscode-utils) buildVscodeExtension buildVscodeMarketplaceExtension;
5in
6+#
7+# Unless there is a good reason not to, we attemp to use the same name as the
8+# extension's unique identifier (the name the extension gets when installed
9+# from vscode under `~/.vscode`) and found on the marketplace extension page.
10+# So an extension's attribute name should be of the form:
11+# "${mktplcRef.publisher}.${mktplcRef.name}".
12+#
13rec {
14+ bbenoist.Nix = buildVscodeMarketplaceExtension {
15 mktplcRef = {
16+ name = "Nix";
17 publisher = "bbenoist";
18 version = "1.0.1";
19 sha256 = "0zd0n9f5z1f0ckzfjr38xw2zzmcxg1gjrava7yahg5cvdcw6l35b";
20 };
21+ meta = with stdenv.lib; {
22+ license = licenses.mit;
23+ };
24 };
25}
+14-25
pkgs/misc/vscode-extensions/vscode-utils.nix
···1-{ stdenv, lib, fetchurl, runCommand, vscode, which }:
23let
4 extendedPkgVersion = lib.getVersion vscode;
···7 mktplcExtRefToFetchArgs = ext: {
8 url = "https://${ext.publisher}.gallery.vsassets.io/_apis/public/gallery/publisher/${ext.publisher}/extension/${ext.name}/${ext.version}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage";
9 sha256 = ext.sha256;
10- name = "${ext.name}.vsix";
0011 };
1213 buildVscodeExtension = a@{
14 name,
15 namePrefix ? "${extendedPkgName}-extension-",
16 src,
00017 configurePhase ? ":",
18 buildPhase ? ":",
19 dontPatchELF ? true,
···21 buildInputs ? [],
22 ...
23 }:
24- stdenv.mkDerivation (a // {
2526 name = namePrefix + name;
27028 inherit configurePhase buildPhase dontPatchELF dontStrip;
2930- # TODO: `which` is an encapsulation leak. It should have been hardwired
31- # as part of the `code` wrapper.
32- buildInputs = [ vscode which ] ++ buildInputs;
33-34- unpackPhase = ''
35- # TODO: Unfortunately, 'code' systematically creates its '.vscode' directory
36- # even tough it has nothing to write in it. We need to redirect this
37- # to a writeable location as the nix environment already has (but
38- # to a non writeable one) otherwise the write will fail.
39- # It would be preferrable if we could intercept / fix this at the source.
40- HOME="$PWD/code_null_home" code \
41- --extensions-dir "$PWD" \
42- --install-extension "${toString src}"
43-44- rm -Rf "$PWD/code_null_home"
45- cd "$(find . -mindepth 1 -type d -print -quit)"
46- ls -la
47- '';
48-4950 installPhase = ''
51- mkdir -p "$out/share/${extendedPkgName}/extensions/${name}"
52- find . -mindepth 1 -maxdepth 1 | xargs mv -t "$out/share/${extendedPkgName}/extensions/${name}/"
53 '';
5455 });
···65 ...
66 }: assert "" == name; assert null == src;
67 buildVscodeExtension ((removeAttrs a [ "mktplcRef" ]) // {
68- name = "${mktplcRef.name}-${mktplcRef.version}";
69 src = fetchVsixFromVscodeMarketplace mktplcRef;
070 });
7172 mktplcRefAttrList = [
···1+{ stdenv, lib, fetchurl, runCommand, vscode, unzip }:
23let
4 extendedPkgVersion = lib.getVersion vscode;
···7 mktplcExtRefToFetchArgs = ext: {
8 url = "https://${ext.publisher}.gallery.vsassets.io/_apis/public/gallery/publisher/${ext.publisher}/extension/${ext.name}/${ext.version}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage";
9 sha256 = ext.sha256;
10+ # The `*.vsix` file is in the end a simple zip file. Change the extension
11+ # so that existing `unzip` hooks takes care of the unpacking.
12+ name = "${ext.publisher}-${ext.name}.zip";
13 };
1415 buildVscodeExtension = a@{
16 name,
17 namePrefix ? "${extendedPkgName}-extension-",
18 src,
19+ # Same as "Unique Identifier" on the extension's web page.
20+ # For the moment, only serve as unique extension dir.
21+ vscodeExtUniqueId,
22 configurePhase ? ":",
23 buildPhase ? ":",
24 dontPatchELF ? true,
···26 buildInputs ? [],
27 ...
28 }:
29+ stdenv.mkDerivation ((removeAttrs a [ "vscodeExtUniqueId" ]) // {
3031 name = namePrefix + name;
3233+ inherit vscodeExtUniqueId;
34 inherit configurePhase buildPhase dontPatchELF dontStrip;
3536+ buildInputs = [ unzip ] ++ buildInputs;
0000000000000000003738 installPhase = ''
39+ mkdir -p "$out/share/${extendedPkgName}/extensions/${vscodeExtUniqueId}"
40+ find . -mindepth 1 -maxdepth 1 | xargs mv -t "$out/share/${extendedPkgName}/extensions/${vscodeExtUniqueId}/"
41 '';
4243 });
···53 ...
54 }: assert "" == name; assert null == src;
55 buildVscodeExtension ((removeAttrs a [ "mktplcRef" ]) // {
56+ name = "${mktplcRef.publisher}-${mktplcRef.name}-${mktplcRef.version}";
57 src = fetchVsixFromVscodeMarketplace mktplcRef;
58+ vscodeExtUniqueId = "${mktplcRef.publisher}.${mktplcRef.name}";
59 });
6061 mktplcRefAttrList = [