Skip to content

Commit

Permalink
vscode: add options to disable update checks
Browse files Browse the repository at this point in the history
Update notification popups are annoying when vscode/vscodium is
managed by Home Manager. However, as these settings also require the
configuration to be managed via `userSettings`, they are disabled by
default.
  • Loading branch information
wamserma authored and rycee committed Oct 27, 2022
1 parent 32fe7d2 commit d3f2161
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 8 deletions.
27 changes: 24 additions & 3 deletions modules/programs/vscode.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ let
# TODO: On Darwin where are the extensions?
extensionPath = ".${extensionDir}/extensions";

mergedUserSettings = cfg.userSettings
// optionalAttrs (!cfg.enableUpdateCheck) { "update.mode" = "none"; }
// optionalAttrs (!cfg.enableExtensionUpdateCheck) {
"extensions.autoCheckUpdates" = false;
};
in {
imports = [
(mkChangedOptionModule [ "programs" "vscode" "immutableExtensionsDir" ] [
Expand All @@ -56,12 +61,28 @@ in {
'';
};

enableUpdateCheck = mkOption {
type = types.bool;
default = true;
description = ''
Whether to enable update checks/notifications.
'';
};

enableExtensionUpdateCheck = mkOption {
type = types.bool;
default = true;
description = ''
Whether to enable update notifications for extensions.
'';
};

userSettings = mkOption {
type = jsonFormat.type;
default = { };
example = literalExpression ''
{
"update.channel" = "none";
"files.autoSave" = "off"
"[nix]"."editor.tabSize" = 2;
}
'';
Expand Down Expand Up @@ -164,9 +185,9 @@ in {
home.packages = [ cfg.package ];

home.file = mkMerge [
(mkIf (cfg.userSettings != { }) {
(mkIf (mergedUserSettings != { }) {
"${configFilePath}".source =
jsonFormat.generate "vscode-user-settings" cfg.userSettings;
jsonFormat.generate "vscode-user-settings" mergedUserSettings;
})
(mkIf (cfg.userTasks != { }) {
"${tasksFilePath}".source =
Expand Down
5 changes: 4 additions & 1 deletion tests/modules/programs/vscode/default.nix
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{ vscode-keybindings = ./keybindings.nix; }
{
vscode-keybindings = ./keybindings.nix;
vscode-update-checks = ./update-checks.nix;
}
16 changes: 12 additions & 4 deletions tests/modules/programs/vscode/keybindings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ let
}
];

targetPath = if pkgs.stdenv.hostPlatform.isDarwin then
keybindingsPath = if pkgs.stdenv.hostPlatform.isDarwin then
"Library/Application Support/Code/User/keybindings.json"
else
".config/Code/User/keybindings.json";

expectedJson = pkgs.writeText "expected.json" ''
settingsPath = if pkgs.stdenv.hostPlatform.isDarwin then
"Library/Application Support/Code/User/settings.json"
else
".config/Code/User/settings.json";

expectedKeybindings = pkgs.writeText "expected.json" ''
[
{
"command": "editor.action.clipboardCopyAction",
Expand All @@ -58,6 +63,7 @@ let
}
]
'';

in {
config = {
programs.vscode = {
Expand All @@ -67,8 +73,10 @@ in {
};

nmt.script = ''
assertFileExists "home-files/${targetPath}"
assertFileContent "home-files/${targetPath}" "${expectedJson}"
assertFileExists "home-files/${keybindingsPath}"
assertFileContent "home-files/${keybindingsPath}" "${expectedKeybindings}"
assertPathNotExists "home-files/${settingsPath}"
'';
};
}
29 changes: 29 additions & 0 deletions tests/modules/programs/vscode/update-checks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{ pkgs, ... }:

let

settingsPath = if pkgs.stdenv.hostPlatform.isDarwin then
"Library/Application Support/Code/User/settings.json"
else
".config/Code/User/settings.json";

expectedSettings = pkgs.writeText "settings-expected.json" ''
{
"extensions.autoCheckUpdates": false,
"update.mode": "none"
}
'';

in {
programs.vscode = {
enable = true;
package = pkgs.writeScriptBin "vscode" "" // { pname = "vscode"; };
enableUpdateCheck = false;
enableExtensionUpdateCheck = false;
};

nmt.script = ''
assertFileExists "home-files/${settingsPath}"
assertFileContent "home-files/${settingsPath}" "${expectedSettings}"
'';
}

0 comments on commit d3f2161

Please sign in to comment.