From 9930c63ec8206e232359240831a32fbaf3c16fd9 Mon Sep 17 00:00:00 2001 From: Reputable2722 <153411261+Reputable2772@users.noreply.github.com> Date: Wed, 17 Jul 2024 16:24:16 +0530 Subject: [PATCH] vscode: add home.activation script Signed-off-by: Reputable2722 <153411261+Reputable2772@users.noreply.github.com> --- modules/programs/vscode.nix | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/modules/programs/vscode.nix b/modules/programs/vscode.nix index 3fea7a171..1ba87850f 100644 --- a/modules/programs/vscode.nix +++ b/modules/programs/vscode.nix @@ -278,14 +278,36 @@ in { home.packages = [ cfg.package ]; - /* * - TODO: Write a home.activation script for ${userDir}/globalStorage/storage.json, appending - every profile in the format `{ "name": , "location": }` to the - userDataProfiles array. + home.activation.vscodeProfiles = hm.dag.entryAfter [ "writeBoundary" ] (let + modifyGlobalStorage = + pkgs.writeShellScript "vscode-global-storage-modify" '' + PATH=${makeBinPath [ pkgs.jq ]}''${PATH:+:}$PATH + file="${userDir}/globalStorage/storage.json" - This file needs to mutable, and cannot be symlinked. This is because the file stores other data, - such as background themes, keybindingReferences, etc. - */ + if [ -f "$file" ]; then + existing_profiles=$(jq '.userDataProfiles // [] | map({ (.name): .location }) | add // {}' $file) + file_write="" + profiles=(${escapeShellArgs (map (v: v.name) cfg.profiles)}) + + for profile in "''${profiles[@]}"; do + if [[ "$(echo $existing_profiles | jq --arg profile $profile 'has ($profile)')" != "true" ]] || [[ "$(echo $existing_profiles | jq --arg profile $profile 'has ($profile)')" == "true" && "$(echo $existing_profiles | jq --arg profile $profile '.[$profile]')" != "\"$profile\"" ]]; then + file_write="$file_write$([ "$file_write" != "" ] && echo "...")$profile" + fi + done + else + for profile in "''${profiles[@]}"; do + file_write="$file_write$([ "$file_write" != "" ] && echo "...")$profile" + done + + echo "{}" > $file + fi + + if [ "$file_write" != "" ]; then + userDataProfiles=$(jq ".userDataProfiles += $(echo $file_write | jq -R 'split(" ") | map({ name: ., location: . })')" $file) + echo $userDataProfiles > $file + fi + ''; + in modifyGlobalStorage.outPath); home.file = mkMerge (flatten [ (map (v: