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";
}.${vscodePname};
userDir = if pkgs.stdenv.hostPlatform.isDarwin then
"Library/Application Support/${configDir}/User"
else
"${config.xdg.configHome}/${configDir}/User";
configFilePath = "${cfg.userDir}/settings.json";
tasksFilePath = "${cfg.userDir}/tasks.json";
keybindingsFilePath = "${cfg.userDir}/keybindings.json";
configFilePath = "${userDir}/settings.json";
tasksFilePath = "${userDir}/tasks.json";
keybindingsFilePath = "${userDir}/keybindings.json";
snippetDir = "${userDir}/snippets";
# TODO: On Darwin where are the extensions?
extensionPath = ".${extensionDir}/extensions";
snippetDir = "${cfg.userDir}/snippets";
extensionJson = pkgs.vscode-utils.toExtensionJson cfg.extensions;
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 {
type = types.bool;
default = true;
@ -223,6 +230,12 @@ in {
};
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.file = mkMerge [
@ -246,7 +259,8 @@ in {
# Adapted from https://discourse.nixos.org/t/vscode-extensions-setup/1801/2
toPaths = ext:
map (k: { "${extensionPath}/${k}".source = "${ext}/${subDir}/${k}"; })
map
(k: { "${cfg.extensionPath}/${k}".source = "${ext}/${subDir}/${k}"; })
(if ext ? vscodeExtUniqueId then
[ ext.vscodeExtUniqueId ]
else
@ -256,17 +270,17 @@ in {
++ 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" = {
"${cfg.extensionPath}/.extensions-immutable.json" = {
text = extensionJson;
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"
run ${getExe cfg.package} --list-extensions > /dev/null
'';
};
})
else {
"${extensionPath}".source = let
"${cfg.extensionPath}".source = let
combinedExtensionsDrv = pkgs.buildEnv {
name = "vscode-extensions";
paths = cfg.extensions