nixpkgs/pkgs/misc/vscode-extensions/vscodeWithConfiguration.nix
Moises Nessim f9d28ed7db Merge branch 'vscode-utils/vscodeEnv' of https://github.com/countoren/nixpkgs-1 into vscode-utils/vscodeEnv
* 'vscode-utils/vscodeEnv' of https://github.com/countoren/nixpkgs-1: (178391 commits)
  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.
  fix permission problem of mutableExtensions
  vscodeEnv updateSettings for keybindings change keybindings file name parameter type from path to string
  change vscodeSettingsFile parameter type from path to string
  add missing jq to vscodeEnv
  use updateSettings in vscodeEnv in order to create and/or update settings.json, keybindings.json
  add updateSettings drv which will union nix settings configurations into the a vscode settings file
  vscode-utils/vscodeEnv: fix typo and grammer in the description comment
  vscode-utils/vscodeEnv: split to 2 functions vscodeWithConfiguration, vscodeExts2nix, vscodeEnv
  vsode-utils: extracting attributes to limit input range
  vscode-utils/vscodeEnv: add vscodeWithConfiguration, vscodeExts2nix and vscodeEnv
  xfce.xfce4-icon-theme: update gtk dependency and add license
  xfce.xfce4-hardware-monitor-plugin: update meta
  xfce.xfce4-embed-plugin: update meta and buildInputs
  xfce.xfce4-mailwatch-plugin: remove broken status
  xfce.exo: add support for gtk2, besides gtk3
  xfce.xfdesktop: 4.14.1 -> 4.14.2
  xfce.xfce4-weather-plugin: 0.8.10 -> 0.10.1
  xfce.xfdashboard: 0.7.5 -> 0.7.7
  xfce.xfce4-timer-plugin: 1.6.0 -> 1.7.0
  ...
2020-05-26 13:16:13 -05:00

54 lines
2.2 KiB
Nix

# wrapper over vscode to control extensions per project (extensions folder will be created in execution path)
{ lib
, writeShellScriptBin
, extensionsFromVscodeMarketplace
, vscodeDefault
}:
## User input
{ vscode ? vscodeDefault
# extensions to be symlinked into the project's extensions folder
, nixExtensions ? []
# 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;
mutExtsDrvs = extensionsFromVscodeMarketplace mutableExtensions;
mutableExtsPaths = lib.forEach mutExtsDrvs ( e:
{
origin = ''${e}/share/vscode/extensions/${e.vscodeExtUniqueId}'';
target = ''${vscodeExtsFolderName}/${e.vscodeExtUniqueId}-${(lib.findSingle (ext: ''${ext.publisher}.${ext.name}'' == e.vscodeExtUniqueId) "" "m" mutableExtensions ).version}'';
}
);
#removed not defined extensions
rmExtensions = lib.optionalString (nixExtensions++mutableExtensions != []) ''
find ${vscodeExtsFolderName} -mindepth 1 -maxdepth 1 ${
lib.concatMapStringsSep " " (e : ''! -iname ${e.publisher}.${e.name} '') nixExtensions
+
lib.concatMapStringsSep " " (e : ''! -iname ${e.publisher}.${e.name}-${e.version} '') mutableExtensions
} -exec rm -rf {} \;
'';
#copy mutable extension out of the nix store
cpExtensions = ''
${lib.concatMapStringsSep "\n" (e : ''ln -sfn ${e}/share/vscode/extensions/* ${vscodeExtsFolderName}/'') nixExtsDrvs}
${lib.concatMapStringsSep "\n" (ePath : ''
if [ ! -d ${ePath.target} ]; then
cp -a ${ePath.origin} ${ePath.target}
chmod -R u+rwx ${ePath.target}
fi
'') mutableExtsPaths}
'';
in
writeShellScriptBin "code" ''
if ! [[ "$@" =~ "--list-extension" ]]; then
mkdir -p "${vscodeExtsFolderName}"
${rmExtensions}
${cpExtensions}
fi
${vscode}/bin/code --extensions-dir "${vscodeExtsFolderName}" ${
lib.optionalString (user-data-dir != "") ''--user-data-dir ${user-data-dir }''
} "$@"
''