From d7a5a28fc30d7576061ccfdd3e8382e7ab56ce19 Mon Sep 17 00:00:00 2001 From: Nathan van Doorn Date: Wed, 8 Feb 2023 11:00:27 +0100 Subject: [PATCH] vscode: add extensions.json file in extensions dir (#3588) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * vscode: add extensions.json file in extensions dir This change generates an 'extensions.json` file the same way that nixpkgs' vscode-with-extensions does, and makes sure it is placed in the directory with the extensions. * vscode: remove leftover trace Co-authored-by: Naïm Favier * vscode: fix adding extensions.json with mutable extension dir Co-authored-by: Naïm Favier * vscode: let vscode regenerate the mutable extensions.json * Remove nixpkgs duplication; only apply on vscodes new enough to need it * Use lib.versionAtLeast Co-authored-by: Naïm Favier * Format vscode.nix --------- Co-authored-by: Naïm Favier --- modules/programs/vscode.nix | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/modules/programs/vscode.nix b/modules/programs/vscode.nix index 27faf39bc..414e74510 100644 --- a/modules/programs/vscode.nix +++ b/modules/programs/vscode.nix @@ -7,6 +7,7 @@ let cfg = config.programs.vscode; vscodePname = cfg.package.pname; + vscodeVersion = cfg.package.version; jsonFormat = pkgs.formats.json { }; @@ -34,6 +35,13 @@ let # TODO: On Darwin where are the extensions? extensionPath = ".${extensionDir}/extensions"; + extensionJson = pkgs.vscode-utils.toExtensionJson cfg.extensions; + extensionJsonFile = pkgs.writeTextFile { + name = "extensions-json"; + destination = "/share/vscode/extensions/extensions.json"; + text = extensionJson; + }; + mergedUserSettings = cfg.userSettings // optionalAttrs (!cfg.enableUpdateCheck) { "update.mode" = "none"; } // optionalAttrs (!cfg.enableExtensionUpdateCheck) { @@ -55,6 +63,7 @@ in { package = mkOption { type = types.package; default = pkgs.vscode; + defaultText = literalExpression "pkgs.vscode"; example = literalExpression "pkgs.vscodium"; description = '' Version of Visual Studio Code to install. @@ -211,12 +220,26 @@ in { else builtins.attrNames (builtins.readDir (ext + "/${subDir}"))); in if cfg.mutableExtensionsDir then - mkMerge (concatMap toPaths cfg.extensions) + mkMerge (concatMap toPaths cfg.extensions + ++ lib.optional (lib.versionAtLeast vscodeVersion "1.74.0") [{ + # Whenever our immutable extensions.json changes, force VSCode to regenerate + # extensions.json with both mutable and immutable extensions. + "${extensionPath}/.extensions-immutable.json" = { + text = extensionJson; + onChange = '' + $DRY_RUN_CMD rm $VERBOSE_ARG -f ${extensionPath}/{extensions.json,.init-default-profile-extensions} + $VERBOSE_ECHO "Regenerating VSCode extensions.json" + $DRY_RUN_CMD ${getExe cfg.package} --list-extensions > /dev/null + ''; + }; + }]) else { "${extensionPath}".source = let combinedExtensionsDrv = pkgs.buildEnv { name = "vscode-extensions"; - paths = cfg.extensions; + paths = cfg.extensions + ++ lib.optional (lib.versionAtLeast vscodeVersion "1.74.0") + [ extensionJsonFile ]; }; in "${combinedExtensionsDrv}/${subDir}"; }))