2019-12-24 18:15:15 +00:00
|
|
|
# wrapper over vscode to control extensions per project (extensions folder will be created in execution path)
|
2019-12-28 21:43:41 +00:00
|
|
|
{ lib
|
|
|
|
, writeShellScriptBin
|
|
|
|
, extensionsFromVscodeMarketplace
|
|
|
|
, vscodeDefault
|
|
|
|
}:
|
|
|
|
## User input
|
|
|
|
{ vscode ? vscodeDefault
|
2019-12-24 18:15:15 +00:00
|
|
|
# extensions to be symlinked into the project's extensions folder
|
2019-12-28 21:43:41 +00:00
|
|
|
, nixExtensions ? []
|
2019-12-24 18:15:15 +00:00
|
|
|
# extensions to be copied into the project's extensions folder
|
2019-12-28 21:43:41 +00:00
|
|
|
, mutableExtensions ? []
|
|
|
|
, vscodeExtsFolderName ? ".vscode-exts"
|
2020-05-22 21:23:01 +01:00
|
|
|
, user-data-dir ? ''"''${TMP}vscodeWithConfiguration/vscode-data-dir"''
|
2019-12-24 18:15:15 +00:00
|
|
|
}:
|
|
|
|
let
|
|
|
|
nixExtsDrvs = extensionsFromVscodeMarketplace nixExtensions;
|
|
|
|
mutExtsDrvs = extensionsFromVscodeMarketplace mutableExtensions;
|
2020-02-20 14:52:06 +00:00
|
|
|
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}'';
|
|
|
|
}
|
|
|
|
);
|
2019-12-24 18:15:15 +00:00
|
|
|
|
|
|
|
#removed not defined extensions
|
|
|
|
rmExtensions = lib.optionalString (nixExtensions++mutableExtensions != []) ''
|
2020-05-26 19:14:35 +01:00
|
|
|
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 {} \;
|
2019-12-24 18:15:15 +00:00
|
|
|
'';
|
|
|
|
#copy mutable extension out of the nix store
|
|
|
|
cpExtensions = ''
|
|
|
|
${lib.concatMapStringsSep "\n" (e : ''ln -sfn ${e}/share/vscode/extensions/* ${vscodeExtsFolderName}/'') nixExtsDrvs}
|
2020-02-20 14:52:06 +00:00
|
|
|
${lib.concatMapStringsSep "\n" (ePath : ''
|
|
|
|
if [ ! -d ${ePath.target} ]; then
|
|
|
|
cp -a ${ePath.origin} ${ePath.target}
|
|
|
|
chmod -R u+rwx ${ePath.target}
|
|
|
|
fi
|
|
|
|
'') mutableExtsPaths}
|
2019-12-24 18:15:15 +00:00
|
|
|
'';
|
|
|
|
in
|
|
|
|
writeShellScriptBin "code" ''
|
|
|
|
if ! [[ "$@" =~ "--list-extension" ]]; then
|
2020-05-22 21:23:01 +01:00
|
|
|
mkdir -p "${vscodeExtsFolderName}"
|
2019-12-24 18:15:15 +00:00
|
|
|
${rmExtensions}
|
|
|
|
${cpExtensions}
|
|
|
|
fi
|
2020-05-22 21:23:01 +01:00
|
|
|
${vscode}/bin/code --extensions-dir "${vscodeExtsFolderName}" ${
|
|
|
|
lib.optionalString (user-data-dir != "") ''--user-data-dir ${user-data-dir }''
|
|
|
|
} "$@"
|
2019-12-24 18:15:15 +00:00
|
|
|
''
|