vscode: add extensions.json file in extensions dir (#3588)
* 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 <n@monade.li> * vscode: fix adding extensions.json with mutable extension dir Co-authored-by: Naïm Favier <n@monade.li> * 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 <n@monade.li> * Format vscode.nix --------- Co-authored-by: Naïm Favier <n@monade.li>
This commit is contained in:
parent
6d95d98b6b
commit
d7a5a28fc3
|
@ -7,6 +7,7 @@ let
|
||||||
cfg = config.programs.vscode;
|
cfg = config.programs.vscode;
|
||||||
|
|
||||||
vscodePname = cfg.package.pname;
|
vscodePname = cfg.package.pname;
|
||||||
|
vscodeVersion = cfg.package.version;
|
||||||
|
|
||||||
jsonFormat = pkgs.formats.json { };
|
jsonFormat = pkgs.formats.json { };
|
||||||
|
|
||||||
|
@ -34,6 +35,13 @@ let
|
||||||
# TODO: On Darwin where are the extensions?
|
# TODO: On Darwin where are the extensions?
|
||||||
extensionPath = ".${extensionDir}/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
|
mergedUserSettings = cfg.userSettings
|
||||||
// optionalAttrs (!cfg.enableUpdateCheck) { "update.mode" = "none"; }
|
// optionalAttrs (!cfg.enableUpdateCheck) { "update.mode" = "none"; }
|
||||||
// optionalAttrs (!cfg.enableExtensionUpdateCheck) {
|
// optionalAttrs (!cfg.enableExtensionUpdateCheck) {
|
||||||
|
@ -55,6 +63,7 @@ in {
|
||||||
package = mkOption {
|
package = mkOption {
|
||||||
type = types.package;
|
type = types.package;
|
||||||
default = pkgs.vscode;
|
default = pkgs.vscode;
|
||||||
|
defaultText = literalExpression "pkgs.vscode";
|
||||||
example = literalExpression "pkgs.vscodium";
|
example = literalExpression "pkgs.vscodium";
|
||||||
description = ''
|
description = ''
|
||||||
Version of Visual Studio Code to install.
|
Version of Visual Studio Code to install.
|
||||||
|
@ -211,12 +220,26 @@ in {
|
||||||
else
|
else
|
||||||
builtins.attrNames (builtins.readDir (ext + "/${subDir}")));
|
builtins.attrNames (builtins.readDir (ext + "/${subDir}")));
|
||||||
in if cfg.mutableExtensionsDir then
|
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 {
|
else {
|
||||||
"${extensionPath}".source = let
|
"${extensionPath}".source = let
|
||||||
combinedExtensionsDrv = pkgs.buildEnv {
|
combinedExtensionsDrv = pkgs.buildEnv {
|
||||||
name = "vscode-extensions";
|
name = "vscode-extensions";
|
||||||
paths = cfg.extensions;
|
paths = cfg.extensions
|
||||||
|
++ lib.optional (lib.versionAtLeast vscodeVersion "1.74.0")
|
||||||
|
[ extensionJsonFile ];
|
||||||
};
|
};
|
||||||
in "${combinedExtensionsDrv}/${subDir}";
|
in "${combinedExtensionsDrv}/${subDir}";
|
||||||
}))
|
}))
|
||||||
|
|
Loading…
Reference in a new issue