2020-06-02 18:00:15 +00:00
|
|
|
# wrapper over vscode to control extensions per project (extensions folder will be created in execution path)
|
2020-09-25 04:45:31 +00:00
|
|
|
{ lib
|
|
|
|
, writeShellScriptBin
|
|
|
|
, extensionsFromVscodeMarketplace
|
2020-06-02 18:00:15 +00:00
|
|
|
, vscodeDefault
|
|
|
|
}:
|
|
|
|
## User input
|
2020-09-25 04:45:31 +00:00
|
|
|
{ vscode ? vscodeDefault
|
2020-06-02 18:00:15 +00:00
|
|
|
# extensions to be symlinked into the project's extensions folder
|
2020-09-25 04:45:31 +00:00
|
|
|
, nixExtensions ? []
|
2020-06-02 18:00:15 +00:00
|
|
|
# extensions to be copied into the project's extensions folder
|
2020-09-25 04:45:31 +00:00
|
|
|
, mutableExtensions ? []
|
|
|
|
, vscodeExtsFolderName ? ".vscode-exts"
|
2020-06-02 18:00:15 +00:00
|
|
|
, user-data-dir ? ''"''${TMP}vscodeWithConfiguration/vscode-data-dir"''
|
|
|
|
}:
|
2020-09-25 04:45:31 +00:00
|
|
|
let
|
2020-06-02 18:00:15 +00:00
|
|
|
nixExtsDrvs = extensionsFromVscodeMarketplace nixExtensions;
|
|
|
|
mutExtsDrvs = extensionsFromVscodeMarketplace mutableExtensions;
|
2020-09-25 04:45:31 +00:00
|
|
|
mutableExtsPaths = lib.forEach mutExtsDrvs ( e:
|
2020-06-02 18:00:15 +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}'';
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
#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
|
2020-09-25 04:45:31 +00:00
|
|
|
'') mutableExtsPaths}
|
2020-06-02 18:00:15 +00:00
|
|
|
'';
|
|
|
|
in
|
|
|
|
writeShellScriptBin "code" ''
|
2020-09-25 04:45:31 +00:00
|
|
|
if ! [[ "$@" =~ "--list-extension" ]]; then
|
|
|
|
mkdir -p "${vscodeExtsFolderName}"
|
2020-06-02 18:00:15 +00:00
|
|
|
${rmExtensions}
|
|
|
|
${cpExtensions}
|
|
|
|
fi
|
2020-09-25 04:45:31 +00:00
|
|
|
${vscode}/bin/code --extensions-dir "${vscodeExtsFolderName}" ${
|
2020-06-02 18:00:15 +00:00
|
|
|
lib.optionalString (user-data-dir != "") ''--user-data-dir ${user-data-dir }''
|
|
|
|
} "$@"
|
|
|
|
''
|