aboutsummaryrefslogtreecommitdiff
path: root/home-manager/modules/programs/vscode.nix
diff options
context:
space:
mode:
Diffstat (limited to 'home-manager/modules/programs/vscode.nix')
-rw-r--r--home-manager/modules/programs/vscode.nix66
1 files changed, 55 insertions, 11 deletions
diff --git a/home-manager/modules/programs/vscode.nix b/home-manager/modules/programs/vscode.nix
index cf7ac722210..099760c834a 100644
--- a/home-manager/modules/programs/vscode.nix
+++ b/home-manager/modules/programs/vscode.nix
@@ -20,11 +20,14 @@ let
"vscodium" = "vscode-oss";
}.${vscodePname};
- configFilePath =
+ userDir =
if pkgs.stdenv.hostPlatform.isDarwin then
- "Library/Application Support/${configDir}/User/settings.json"
+ "Library/Application Support/${configDir}/User"
else
- "${config.xdg.configHome}/${configDir}/User/settings.json";
+ "${config.xdg.configHome}/${configDir}/User";
+
+ configFilePath = "${userDir}/settings.json";
+ keybindingsFilePath = "${userDir}/keybindings.json";
# TODO: On Darwin where are the extensions?
extensionPath = ".${extensionDir}/extensions";
@@ -59,6 +62,45 @@ in
'';
};
+ keybindings = mkOption {
+ type = types.listOf (types.submodule {
+ options = {
+ key = mkOption {
+ type = types.str;
+ example = "ctrl+c";
+ description = "The key or key-combination to bind.";
+ };
+
+ command = mkOption {
+ type = types.str;
+ example = "editor.action.clipboardCopyAction";
+ description = "The VS Code command to execute.";
+ };
+
+ when = mkOption {
+ type = types.str;
+ default = "";
+ example = "textInputFocus";
+ description = "Optional context filter.";
+ };
+ };
+ });
+ default = [];
+ example = literalExample ''
+ [
+ {
+ key = "ctrl+c";
+ command = "editor.action.clipboardCopyAction";
+ when = "textInputFocus";
+ }
+ ]
+ '';
+ description = ''
+ Keybindings written to Visual Studio Code's
+ <filename>keybindings.json</filename>.
+ '';
+ };
+
extensions = mkOption {
type = types.listOf types.package;
default = [];
@@ -77,15 +119,13 @@ in
# Adapted from https://discourse.nixos.org/t/vscode-extensions-setup/1801/2
home.file =
let
+ subDir = "share/vscode/extensions";
toPaths = path:
- let
- p = "${path}/share/vscode/extensions";
- in
- # Links every dir in p to the extension path.
- mapAttrsToList (k: v:
- {
- "${extensionPath}/${k}".source = "${p}/${k}";
- }) (builtins.readDir p);
+ # Links every dir in path to the extension path.
+ mapAttrsToList (k: _:
+ {
+ "${extensionPath}/${k}".source = "${path}/${subDir}/${k}";
+ }) (builtins.readDir (path + "/${subDir}"));
toSymlink = concatMap toPaths cfg.extensions;
in
foldr
@@ -95,6 +135,10 @@ in
mkIf (cfg.userSettings != {}) {
text = builtins.toJSON cfg.userSettings;
};
+ "${keybindingsFilePath}" =
+ mkIf (cfg.keybindings != []) {
+ text = builtins.toJSON cfg.keybindings;
+ };
}
toSymlink;
};