mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-01-18 02:44:30 +00:00
Use a different vscode user-data-dir for every project.
Treat workspace setting files as global for that user-data-dir with symlink. Add updateLaunchCmd to update .vscode/launch.json.
This commit is contained in:
parent
3816b9d036
commit
673b122836
@ -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}
|
||||
''
|
||||
)
|
||||
)
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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 ];
|
||||
}
|
||||
|
@ -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 }''
|
||||
} "$@"
|
||||
''
|
||||
|
Loading…
Reference in New Issue
Block a user