diff --git a/pkgs/misc/vscode-extensions/updateSettings.nix b/pkgs/misc/vscode-extensions/updateSettings.nix index 7f4a817e5e8b..a033229c5898 100644 --- a/pkgs/misc/vscode-extensions/updateSettings.nix +++ b/pkgs/misc/vscode-extensions/updateSettings.nix @@ -9,6 +9,8 @@ # if marked as true will create an empty json file if does not exists , createIfDoesNotExists ? true , vscodeSettingsFile ? ".vscode/settings.json" +, userSettingsFolder ? "" +, symlinkFromUserSetting ? false }: let @@ -20,13 +22,18 @@ let )''; createEmptySettingsCmd = ''mkdir -p .vscode && echo "{}" > ${vscodeSettingsFile}''; + fileName = builtins.baseNameOf vscodeSettingsFile; + symlinkFromUserSettingCmd = lib.optionalString symlinkFromUserSetting + '' && mkdir -p "${userSettingsFolder}" && ln -sfv "$(pwd)/${vscodeSettingsFile}" "${userSettingsFolder}/" ''; in - writeShellScriptBin ''vscodeNixUpdate-${lib.removeSuffix ".json" (builtins.baseNameOf vscodeSettingsFile)}'' + writeShellScriptBin ''vscodeNixUpdate-${lib.removeSuffix ".json" (fileName)}'' (lib.optionalString (settings != {}) - (if createIfDoesNotExists then '' - [ ! -f "${vscodeSettingsFile}" ] && ${createEmptySettingsCmd} - ${updateVSCodeSettingsCmd} - '' - else ''[ -f "${vscodeSettingsFile}" ] && ${updateVSCodeSettingsCmd}'' - )) + (if createIfDoesNotExists then '' + [ ! -f "${vscodeSettingsFile}" ] && ${createEmptySettingsCmd} + ${updateVSCodeSettingsCmd} ${symlinkFromUserSettingCmd} + '' + else ''[ -f "${vscodeSettingsFile}" ] && ${updateVSCodeSettingsCmd} ${symlinkFromUserSettingCmd} + '' + ) + ) diff --git a/pkgs/misc/vscode-extensions/vscode-utils.nix b/pkgs/misc/vscode-extensions/vscode-utils.nix index 5c49b226ebcd..a5382c1c231c 100644 --- a/pkgs/misc/vscode-extensions/vscode-utils.nix +++ b/pkgs/misc/vscode-extensions/vscode-utils.nix @@ -1,9 +1,13 @@ { stdenv, lib, buildEnv, writeShellScriptBin, fetchurl, vscode, unzip, jq }: let + extendedPkgVersion = lib.getVersion vscode; + extendedPkgName = lib.removeSuffix "-${extendedPkgVersion}" vscode.name; + buildVscodeExtension = a@{ name, + namePrefix ? "${extendedPkgName}-extension-", src, # Same as "Unique Identifier" on the extension's web page. # For the moment, only serve as unique extension dir. @@ -17,12 +21,12 @@ let }: stdenv.mkDerivation ((removeAttrs a [ "vscodeExtUniqueId" ]) // { - name = "vscode-extension-${name}"; + name = namePrefix + name; inherit vscodeExtUniqueId; inherit configurePhase buildPhase dontPatchELF dontStrip; - installPrefix = "${vscodeExtUniqueId}"; + installPrefix = "share/${extendedPkgName}/extensions/${vscodeExtUniqueId}"; buildInputs = [ unzip ] ++ buildInputs; diff --git a/pkgs/misc/vscode-extensions/vscodeEnv.nix b/pkgs/misc/vscode-extensions/vscodeEnv.nix index 42a46674b27f..6e4bb7b3ea88 100644 --- a/pkgs/misc/vscode-extensions/vscodeEnv.nix +++ b/pkgs/misc/vscode-extensions/vscodeEnv.nix @@ -13,9 +13,12 @@ # will add to the command updateSettings (which will run on executing vscode) settings to override in settings.json file , settings ? {} , createSettingsIfDoesNotExists ? true +, launch ? {} +, createLaunchIfDoesNotExists ? true # will add to the command updateKeybindings(which will run on executing vscode) keybindings to override in keybinding.json file , keybindings ? {} , createKeybindingsIfDoesNotExists ? true +, user-data-dir ? ''"''${TMP}''${name}"/vscode-data-dir'' # if file exists will use it and import the extensions in it into this dervation else will use empty extensions list # this file will be created/updated by vscodeExts2nix when vscode exists , mutableExtensionsFile @@ -29,20 +32,35 @@ let vscodeDefault = vscode; } { - inherit nixExtensions mutableExtensions vscodeExtsFolderName; + inherit nixExtensions mutableExtensions vscodeExtsFolderName user-data-dir; }; updateSettings = import ./updateSettings.nix { inherit lib writeShellScriptBin jq; }; + userSettingsFolder = "${ user-data-dir }/User"; updateSettingsCmd = updateSettings { - inherit settings; + settings = { + "extensions.autoCheckUpdates" = false; + "extensions.autoUpdate" = false; + "update.mode" = "none"; + } // settings; + inherit userSettingsFolder; createIfDoesNotExists = createSettingsIfDoesNotExists; + symlinkFromUserSetting = (user-data-dir != ""); + }; + + updateLaunchCmd = updateSettings { + settings = launch; + createIfDoesNotExists = createLaunchIfDoesNotExists; + vscodeSettingsFile = ".vscode/launch.json"; }; updateKeybindingsCmd = updateSettings { settings = keybindings; createIfDoesNotExists = createKeybindingsIfDoesNotExists; vscodeSettingsFile = ".vscode/keybindings.json"; + inherit userSettingsFolder; + symlinkFromUserSetting = (user-data-dir != ""); }; vscodeExts2nix = import ./vscodeExts2nix.nix { @@ -55,6 +73,7 @@ let }; code = writeShellScriptBin "code" '' ${updateSettingsCmd}/bin/vscodeNixUpdate-settings + ${updateLaunchCmd}/bin/vscodeNixUpdate-launch ${updateKeybindingsCmd}/bin/vscodeNixUpdate-keybindings ${vscodeWithConfiguration}/bin/code --wait "$@" echo 'running vscodeExts2nix to update ${mutableExtensionsFilePath}...' @@ -63,5 +82,5 @@ let in buildEnv { name = "vscodeEnv"; - paths = [ code vscodeExts2nix updateSettingsCmd updateKeybindingsCmd ]; + paths = [ code vscodeExts2nix updateSettingsCmd updateLaunchCmd updateKeybindingsCmd ]; } diff --git a/pkgs/misc/vscode-extensions/vscodeWithConfiguration.nix b/pkgs/misc/vscode-extensions/vscodeWithConfiguration.nix index b081157e653e..83cf84586b86 100644 --- a/pkgs/misc/vscode-extensions/vscodeWithConfiguration.nix +++ b/pkgs/misc/vscode-extensions/vscodeWithConfiguration.nix @@ -11,6 +11,7 @@ # extensions to be copied into the project's extensions folder , mutableExtensions ? [] , vscodeExtsFolderName ? ".vscode-exts" +, user-data-dir ? ''"''${TMP}vscodeWithConfiguration/vscode-data-dir"'' }: let nixExtsDrvs = extensionsFromVscodeMarketplace nixExtensions; @@ -39,9 +40,11 @@ let in writeShellScriptBin "code" '' if ! [[ "$@" =~ "--list-extension" ]]; then - mkdir -p ${vscodeExtsFolderName} + mkdir -p "${vscodeExtsFolderName}" ${rmExtensions} ${cpExtensions} fi - ${vscode}/bin/code --extensions-dir ${vscodeExtsFolderName} "$@" + ${vscode}/bin/code --extensions-dir "${vscodeExtsFolderName}" ${ + lib.optionalString (user-data-dir != "") ''--user-data-dir ${user-data-dir }'' + } "$@" ''