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