mirror of
https://github.com/nix-community/home-manager
synced 2024-11-23 03:29:45 +01:00
vscode: Get paths from product.json
The VSCode packages contain a product.json which is used to determine the extension and config dirs. Instead of hardcoding the package name, this change parses this file (which may appear in one of two places) and uses that to generate the paths. This hopefully allows more VSCode derivatives to "just work" without home-manager updates.
This commit is contained in:
parent
038630363e
commit
6f7f29f672
6 changed files with 24 additions and 17 deletions
|
@ -11,19 +11,17 @@ let
|
|||
|
||||
jsonFormat = pkgs.formats.json { };
|
||||
|
||||
configDir = {
|
||||
"vscode" = "Code";
|
||||
"vscode-insiders" = "Code - Insiders";
|
||||
"vscodium" = "VSCodium";
|
||||
"openvscode-server" = "OpenVSCode Server";
|
||||
}.${vscodePname};
|
||||
productInfoPath =
|
||||
if pathExists "${cfg.package}/lib/vscode/resources/app/product.json" then
|
||||
# Visual Studio Code, VSCodium
|
||||
"${cfg.package}/lib/vscode/resources/app/product.json"
|
||||
else
|
||||
# OpenVSCode Server
|
||||
"${cfg.package}/product.json";
|
||||
productInfo = lib.importJSON productInfoPath;
|
||||
|
||||
extensionDir = {
|
||||
"vscode" = "vscode";
|
||||
"vscode-insiders" = "vscode-insiders";
|
||||
"vscodium" = "vscode-oss";
|
||||
"openvscode-server" = "openvscode-server";
|
||||
}.${vscodePname};
|
||||
configDir = productInfo.nameShort;
|
||||
extensionDir = productInfo.dataFolderName;
|
||||
|
||||
userDir = if pkgs.stdenv.hostPlatform.isDarwin then
|
||||
"Library/Application Support/${configDir}/User"
|
||||
|
@ -37,7 +35,7 @@ let
|
|||
snippetDir = "${userDir}/snippets";
|
||||
|
||||
# TODO: On Darwin where are the extensions?
|
||||
extensionPath = ".${extensionDir}/extensions";
|
||||
extensionPath = "${extensionDir}/extensions";
|
||||
|
||||
extensionJson = pkgs.vscode-utils.toExtensionJson cfg.extensions;
|
||||
extensionJsonFile = pkgs.writeTextFile {
|
||||
|
|
9
tests/modules/programs/vscode/fake-pkg.nix
Normal file
9
tests/modules/programs/vscode/fake-pkg.nix
Normal file
|
@ -0,0 +1,9 @@
|
|||
{ pkgs, ... }:
|
||||
pkgs.writeTextFile {
|
||||
name = "fake-vscode";
|
||||
destination = "/lib/vscode/resources/app/product.json";
|
||||
text = builtins.toJSON {
|
||||
nameShort = "Code";
|
||||
dataFolderName = ".vscode";
|
||||
};
|
||||
}
|
|
@ -66,7 +66,7 @@ in {
|
|||
programs.vscode = {
|
||||
enable = true;
|
||||
keybindings = bindings;
|
||||
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; };
|
||||
package = import ./fake-pkg.nix pkgs;
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
|
|
|
@ -42,7 +42,7 @@ let
|
|||
in {
|
||||
programs.vscode = {
|
||||
enable = true;
|
||||
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; };
|
||||
package = import ./fake-pkg.nix pkgs;
|
||||
globalSnippets = {
|
||||
fixme = {
|
||||
prefix = [ "fixme" ];
|
||||
|
|
|
@ -32,7 +32,7 @@ let
|
|||
in {
|
||||
programs.vscode = {
|
||||
enable = true;
|
||||
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; };
|
||||
package = import ./fake-pkg.nix pkgs;
|
||||
userTasks = tasks;
|
||||
};
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ let
|
|||
in {
|
||||
programs.vscode = {
|
||||
enable = true;
|
||||
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; };
|
||||
package = import ./fake-pkg.nix pkgs;
|
||||
enableUpdateCheck = false;
|
||||
enableExtensionUpdateCheck = false;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue