Fix invalid pythonImportsCheck attributes (#374927)
[NixPkgs.git] / pkgs / applications / editors / vscode / with-extensions.nix
blob5097d177d6242798cdcd44f91bcf9a43078a5c47
2   lib,
3   stdenv,
4   runCommand,
5   buildEnv,
6   vscode,
7   vscode-utils,
8   makeWrapper,
9   writeTextFile,
10   vscodeExtensions ? [ ],
14   `vscodeExtensions`
15    :  A set of vscode extensions to be installed alongside the editor. Here's a an
16       example:
18       ~~~
19       vscode-with-extensions.override {
21         # When the extension is already available in the default extensions set.
22         vscodeExtensions = with vscode-extensions; [
23           bbenoist.nix
24         ]
26         # Concise version from the vscode market place when not available in the default set.
27         ++ vscode-utils.extensionsFromVscodeMarketplace [
28           {
29             name = "code-runner";
30             publisher = "formulahendry";
31             version = "0.6.33";
32             sha256 = "166ia73vrcl5c9hm4q1a73qdn56m0jc7flfsk5p5q41na9f10lb0";
33           }
34         ];
35       }
36       ~~~
38       This expression should fetch
39        -  the *nix* vscode extension from whatever source defined in the
40           default nixpkgs extensions set `vscodeExtensions`.
42        -  the *code-runner* vscode extension from the marketplace using the
43           following url:
45           ~~~
46           https://bbenoist.gallery.vsassets.io/_apis/public/gallery/publisher/bbenoist/extension/nix/1.0.1/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage
47           ~~~
49       The original `code` executable will be wrapped so that it uses the set of pre-installed / unpacked
50       extensions as its `--extensions-dir`.
53 let
54   inherit (vscode) executableName longName;
55   wrappedPkgVersion = lib.getVersion vscode;
56   wrappedPkgName = lib.removeSuffix "-${wrappedPkgVersion}" vscode.name;
58   extensionJsonFile = writeTextFile {
59     name = "vscode-extensions-json";
60     destination = "/share/vscode/extensions/extensions.json";
61     text = vscode-utils.toExtensionJson vscodeExtensions;
62   };
64   combinedExtensionsDrv = buildEnv {
65     name = "vscode-extensions";
66     paths = vscodeExtensions ++ [ extensionJsonFile ];
67   };
69   extensionsFlag = ''
70     --add-flags "--extensions-dir ${combinedExtensionsDrv}/share/vscode/extensions"
71   '';
74 runCommand "${wrappedPkgName}-with-extensions-${wrappedPkgVersion}"
75   {
76     nativeBuildInputs = [ makeWrapper ];
77     buildInputs = [ vscode ];
78     dontPatchELF = true;
79     dontStrip = true;
80     meta = vscode.meta;
81   }
82   (
83     if stdenv.hostPlatform.isDarwin then
84       ''
85         mkdir -p $out/bin/
86         mkdir -p "$out/Applications/${longName}.app/Contents/MacOS"
88         for path in PkgInfo Frameworks Resources _CodeSignature Info.plist; do
89           ln -s "${vscode}/Applications/${longName}.app/Contents/$path" "$out/Applications/${longName}.app/Contents/"
90         done
92         makeWrapper "${vscode}/bin/${executableName}" "$out/bin/${executableName}" ${extensionsFlag}
93         makeWrapper "${vscode}/Applications/${longName}.app/Contents/MacOS/Electron" "$out/Applications/${longName}.app/Contents/MacOS/Electron" ${extensionsFlag}
94       ''
95     else
96       ''
97         mkdir -p "$out/bin"
98         mkdir -p "$out/share/applications"
99         mkdir -p "$out/share/pixmaps"
101         ln -sT "${vscode}/share/pixmaps/vs${executableName}.png" "$out/share/pixmaps/vs${executableName}.png"
102         ln -sT "${vscode}/share/applications/${executableName}.desktop" "$out/share/applications/${executableName}.desktop"
103         ln -sT "${vscode}/share/applications/${executableName}-url-handler.desktop" "$out/share/applications/${executableName}-url-handler.desktop"
104         makeWrapper "${vscode}/bin/${executableName}" "$out/bin/${executableName}" ${extensionsFlag}
105       ''
106   )