1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2024-12-14 11:57:55 +00: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:
Ross Brunton 2024-10-09 01:34:51 +01:00
parent 038630363e
commit 6f7f29f672
No known key found for this signature in database
GPG key ID: 7ADCA0DE7E26C278
6 changed files with 24 additions and 17 deletions

View file

@ -11,19 +11,17 @@ let
jsonFormat = pkgs.formats.json { }; jsonFormat = pkgs.formats.json { };
configDir = { productInfoPath =
"vscode" = "Code"; if pathExists "${cfg.package}/lib/vscode/resources/app/product.json" then
"vscode-insiders" = "Code - Insiders"; # Visual Studio Code, VSCodium
"vscodium" = "VSCodium"; "${cfg.package}/lib/vscode/resources/app/product.json"
"openvscode-server" = "OpenVSCode Server"; else
}.${vscodePname}; # OpenVSCode Server
"${cfg.package}/product.json";
productInfo = lib.importJSON productInfoPath;
extensionDir = { configDir = productInfo.nameShort;
"vscode" = "vscode"; extensionDir = productInfo.dataFolderName;
"vscode-insiders" = "vscode-insiders";
"vscodium" = "vscode-oss";
"openvscode-server" = "openvscode-server";
}.${vscodePname};
userDir = if pkgs.stdenv.hostPlatform.isDarwin then userDir = if pkgs.stdenv.hostPlatform.isDarwin then
"Library/Application Support/${configDir}/User" "Library/Application Support/${configDir}/User"
@ -37,7 +35,7 @@ let
snippetDir = "${userDir}/snippets"; snippetDir = "${userDir}/snippets";
# 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; extensionJson = pkgs.vscode-utils.toExtensionJson cfg.extensions;
extensionJsonFile = pkgs.writeTextFile { extensionJsonFile = pkgs.writeTextFile {

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

View file

@ -66,7 +66,7 @@ in {
programs.vscode = { programs.vscode = {
enable = true; enable = true;
keybindings = bindings; keybindings = bindings;
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; }; package = import ./fake-pkg.nix pkgs;
}; };
nmt.script = '' nmt.script = ''

View file

@ -42,7 +42,7 @@ let
in { in {
programs.vscode = { programs.vscode = {
enable = true; enable = true;
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; }; package = import ./fake-pkg.nix pkgs;
globalSnippets = { globalSnippets = {
fixme = { fixme = {
prefix = [ "fixme" ]; prefix = [ "fixme" ];

View file

@ -32,7 +32,7 @@ let
in { in {
programs.vscode = { programs.vscode = {
enable = true; enable = true;
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; }; package = import ./fake-pkg.nix pkgs;
userTasks = tasks; userTasks = tasks;
}; };

View file

@ -17,7 +17,7 @@ let
in { in {
programs.vscode = { programs.vscode = {
enable = true; enable = true;
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; }; package = import ./fake-pkg.nix pkgs;
enableUpdateCheck = false; enableUpdateCheck = false;
enableExtensionUpdateCheck = false; enableExtensionUpdateCheck = false;
}; };