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}"; }))