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