nixpkgs/pkgs/misc/vscode-extensions/vscodeWithConfiguration.nix

55 lines
2.1 KiB
Nix
Raw Normal View History

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