graphene-hardened-malloc: 2024123000 -> 2025012700 (#378307)
[NixPkgs.git] / pkgs / applications / editors / vscode / extensions / vscodeEnv.nix
blob37b82075e7518215919fd631a3ff7f8143473d3f
1 #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.
3   lib,
4   buildEnv,
5   writeShellScriptBin,
6   extensionsFromVscodeMarketplace,
7   vscodeDefault,
8   jq,
9 }:
10 ##User input
12   vscode ? vscodeDefault,
13   nixExtensions ? [ ],
14   vscodeExtsFolderName ? ".vscode-exts",
15   # will add to the command updateSettings (which will run on executing vscode) settings to override in settings.json file
16   settings ? { },
17   createSettingsIfDoesNotExists ? true,
18   launch ? { },
19   createLaunchIfDoesNotExists ? true,
20   # will add to the command updateKeybindings(which will run on executing vscode) keybindings to override in keybinding.json file
21   keybindings ? { },
22   createKeybindingsIfDoesNotExists ? true,
23   user-data-dir ? ''"''${TMP}''${name}"/vscode-data-dir'',
24   # if file exists will use it and import the extensions in it into this derivation else will use empty extensions list
25   # this file will be created/updated by vscodeExts2nix when vscode exists
26   mutableExtensionsFile,
28 let
29   mutableExtensionsFilePath = toString mutableExtensionsFile;
30   mutableExtensions = lib.optionals (builtins.pathExists mutableExtensionsFile) (
31     import mutableExtensionsFilePath
32   );
33   vscodeWithConfiguration =
34     import ./vscodeWithConfiguration.nix
35       {
36         inherit lib writeShellScriptBin extensionsFromVscodeMarketplace;
37         vscodeDefault = vscode;
38       }
39       {
40         inherit
41           nixExtensions
42           mutableExtensions
43           vscodeExtsFolderName
44           user-data-dir
45           ;
46       };
48   updateSettings = import ./updateSettings.nix { inherit lib writeShellScriptBin jq; };
49   userSettingsFolder = "${user-data-dir}/User";
51   updateSettingsCmd = updateSettings {
52     settings = {
53       "extensions.autoCheckUpdates" = false;
54       "extensions.autoUpdate" = false;
55       "update.mode" = "none";
56     } // settings;
57     inherit userSettingsFolder;
58     createIfDoesNotExists = createSettingsIfDoesNotExists;
59     symlinkFromUserSetting = (user-data-dir != "");
60   };
62   updateLaunchCmd = updateSettings {
63     settings = launch;
64     createIfDoesNotExists = createLaunchIfDoesNotExists;
65     vscodeSettingsFile = ".vscode/launch.json";
66   };
68   updateKeybindingsCmd = updateSettings {
69     settings = keybindings;
70     createIfDoesNotExists = createKeybindingsIfDoesNotExists;
71     vscodeSettingsFile = ".vscode/keybindings.json";
72     inherit userSettingsFolder;
73     symlinkFromUserSetting = (user-data-dir != "");
74   };
76   vscodeExts2nix =
77     import ./vscodeExts2nix.nix
78       {
79         inherit lib writeShellScriptBin;
80         vscodeDefault = vscodeWithConfiguration;
81       }
82       {
83         extensionsToIgnore = nixExtensions;
84         extensions = mutableExtensions;
85       };
86   code = writeShellScriptBin "code" ''
87     ${updateSettingsCmd}/bin/vscodeNixUpdate-settings
88     ${updateLaunchCmd}/bin/vscodeNixUpdate-launch
89     ${updateKeybindingsCmd}/bin/vscodeNixUpdate-keybindings
90     ${vscodeWithConfiguration}/bin/code --wait "$@"
91     echo 'running vscodeExts2nix to update ${mutableExtensionsFilePath}...'
92     ${vscodeExts2nix}/bin/vscodeExts2nix > ${mutableExtensionsFilePath}
93   '';
95 buildEnv {
96   name = "vscodeEnv";
97   paths = [
98     code
99     vscodeExts2nix
100     updateSettingsCmd
101     updateLaunchCmd
102     updateKeybindingsCmd
103   ];