1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2024-12-14 11:57:55 +00:00

vscode: add support for codeoss-cloudworkstations

On these machines vscode is preinstalled and configured to read from
~/.codeoss-cloudworkstations
This commit is contained in:
Terje Larsen 2024-06-21 01:57:33 +02:00
parent 509dbf8d45
commit 4ae09e7cd8
No known key found for this signature in database
GPG key ID: DE147A553FC5AB4A

View file

@ -25,19 +25,11 @@ let
"openvscode-server" = "openvscode-server"; "openvscode-server" = "openvscode-server";
}.${vscodePname}; }.${vscodePname};
userDir = if pkgs.stdenv.hostPlatform.isDarwin then configFilePath = "${cfg.userDir}/settings.json";
"Library/Application Support/${configDir}/User" tasksFilePath = "${cfg.userDir}/tasks.json";
else keybindingsFilePath = "${cfg.userDir}/keybindings.json";
"${config.xdg.configHome}/${configDir}/User";
configFilePath = "${userDir}/settings.json"; snippetDir = "${cfg.userDir}/snippets";
tasksFilePath = "${userDir}/tasks.json";
keybindingsFilePath = "${userDir}/keybindings.json";
snippetDir = "${userDir}/snippets";
# TODO: On Darwin where are the extensions?
extensionPath = ".${extensionDir}/extensions";
extensionJson = pkgs.vscode-utils.toExtensionJson cfg.extensions; extensionJson = pkgs.vscode-utils.toExtensionJson cfg.extensions;
extensionJsonFile = pkgs.writeTextFile { extensionJsonFile = pkgs.writeTextFile {
@ -74,6 +66,21 @@ in {
''; '';
}; };
extensionPath = mkOption {
type = types.str;
default = ".${extensionDir}/extensions";
description = ''
The path where extensions should be installed.
'';
};
userDir = mkOption {
type = types.str;
description = ''
The path where user configuration is stored.
'';
};
enableUpdateCheck = mkOption { enableUpdateCheck = mkOption {
type = types.bool; type = types.bool;
default = true; default = true;
@ -223,6 +230,12 @@ in {
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
programs.vscode.userDir = lib.mkDefault
(if pkgs.stdenv.hostPlatform.isDarwin then
"Library/Application Support/${configDir}/User"
else
"${config.xdg.configHome}/${configDir}/User");
home.packages = [ cfg.package ]; home.packages = [ cfg.package ];
home.file = mkMerge [ home.file = mkMerge [
@ -246,7 +259,8 @@ in {
# Adapted from https://discourse.nixos.org/t/vscode-extensions-setup/1801/2 # Adapted from https://discourse.nixos.org/t/vscode-extensions-setup/1801/2
toPaths = ext: toPaths = ext:
map (k: { "${extensionPath}/${k}".source = "${ext}/${subDir}/${k}"; }) map
(k: { "${cfg.extensionPath}/${k}".source = "${ext}/${subDir}/${k}"; })
(if ext ? vscodeExtUniqueId then (if ext ? vscodeExtUniqueId then
[ ext.vscodeExtUniqueId ] [ ext.vscodeExtUniqueId ]
else else
@ -256,17 +270,17 @@ in {
++ lib.optional (lib.versionAtLeast vscodeVersion "1.74.0") { ++ lib.optional (lib.versionAtLeast vscodeVersion "1.74.0") {
# Whenever our immutable extensions.json changes, force VSCode to regenerate # Whenever our immutable extensions.json changes, force VSCode to regenerate
# extensions.json with both mutable and immutable extensions. # extensions.json with both mutable and immutable extensions.
"${extensionPath}/.extensions-immutable.json" = { "${cfg.extensionPath}/.extensions-immutable.json" = {
text = extensionJson; text = extensionJson;
onChange = '' onChange = ''
run rm $VERBOSE_ARG -f ${extensionPath}/{extensions.json,.init-default-profile-extensions} run rm $VERBOSE_ARG -f ${cfg.extensionPath}/{extensions.json,.init-default-profile-extensions}
verboseEcho "Regenerating VSCode extensions.json" verboseEcho "Regenerating VSCode extensions.json"
run ${getExe cfg.package} --list-extensions > /dev/null run ${getExe cfg.package} --list-extensions > /dev/null
''; '';
}; };
}) })
else { else {
"${extensionPath}".source = let "${cfg.extensionPath}".source = let
combinedExtensionsDrv = pkgs.buildEnv { combinedExtensionsDrv = pkgs.buildEnv {
name = "vscode-extensions"; name = "vscode-extensions";
paths = cfg.extensions paths = cfg.extensions