1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-26 21:19: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:
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 { };
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 {

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 = {
enable = true;
keybindings = bindings;
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; };
package = import ./fake-pkg.nix pkgs;
};
nmt.script = ''

View file

@ -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" ];

View file

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

View file

@ -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;
};