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.
6 extensionsFromVscodeMarketplace,
12 vscode ? vscodeDefault,
14 vscodeExtsFolderName ? ".vscode-exts",
15 # will add to the command updateSettings (which will run on executing vscode) settings to override in settings.json file
17 createSettingsIfDoesNotExists ? true,
19 createLaunchIfDoesNotExists ? true,
20 # will add to the command updateKeybindings(which will run on executing vscode) keybindings to override in keybinding.json file
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,
29 mutableExtensionsFilePath = toString mutableExtensionsFile;
30 mutableExtensions = lib.optionals (builtins.pathExists mutableExtensionsFile) (
31 import mutableExtensionsFilePath
33 vscodeWithConfiguration =
34 import ./vscodeWithConfiguration.nix
36 inherit lib writeShellScriptBin extensionsFromVscodeMarketplace;
37 vscodeDefault = vscode;
48 updateSettings = import ./updateSettings.nix { inherit lib writeShellScriptBin jq; };
49 userSettingsFolder = "${user-data-dir}/User";
51 updateSettingsCmd = updateSettings {
53 "extensions.autoCheckUpdates" = false;
54 "extensions.autoUpdate" = false;
55 "update.mode" = "none";
57 inherit userSettingsFolder;
58 createIfDoesNotExists = createSettingsIfDoesNotExists;
59 symlinkFromUserSetting = (user-data-dir != "");
62 updateLaunchCmd = updateSettings {
64 createIfDoesNotExists = createLaunchIfDoesNotExists;
65 vscodeSettingsFile = ".vscode/launch.json";
68 updateKeybindingsCmd = updateSettings {
69 settings = keybindings;
70 createIfDoesNotExists = createKeybindingsIfDoesNotExists;
71 vscodeSettingsFile = ".vscode/keybindings.json";
72 inherit userSettingsFolder;
73 symlinkFromUserSetting = (user-data-dir != "");
77 import ./vscodeExts2nix.nix
79 inherit lib writeShellScriptBin;
80 vscodeDefault = vscodeWithConfiguration;
83 extensionsToIgnore = nixExtensions;
84 extensions = mutableExtensions;
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}