2018-11-19 16:50:35 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.vscode;
|
|
|
|
|
2019-07-29 20:39:25 +00:00
|
|
|
vscodePname = cfg.package.pname;
|
|
|
|
|
2020-11-30 02:54:55 +00:00
|
|
|
jsonFormat = pkgs.formats.json { };
|
|
|
|
|
2019-07-29 20:39:25 +00:00
|
|
|
configDir = {
|
|
|
|
"vscode" = "Code";
|
|
|
|
"vscode-insiders" = "Code - Insiders";
|
2019-11-11 16:50:34 +00:00
|
|
|
"vscodium" = "VSCodium";
|
2019-07-29 20:39:25 +00:00
|
|
|
}.${vscodePname};
|
|
|
|
|
2019-12-06 13:00:28 +00:00
|
|
|
extensionDir = {
|
|
|
|
"vscode" = "vscode";
|
|
|
|
"vscode-insiders" = "vscode-insiders";
|
|
|
|
"vscodium" = "vscode-oss";
|
|
|
|
}.${vscodePname};
|
|
|
|
|
2020-10-12 20:51:12 +00:00
|
|
|
userDir = if pkgs.stdenv.hostPlatform.isDarwin then
|
|
|
|
"Library/Application Support/${configDir}/User"
|
|
|
|
else
|
|
|
|
"${config.xdg.configHome}/${configDir}/User";
|
2020-06-22 18:48:22 +00:00
|
|
|
|
|
|
|
configFilePath = "${userDir}/settings.json";
|
|
|
|
keybindingsFilePath = "${userDir}/keybindings.json";
|
2019-07-07 17:15:47 +00:00
|
|
|
|
2019-07-29 20:39:25 +00:00
|
|
|
# TODO: On Darwin where are the extensions?
|
2019-12-06 13:00:28 +00:00
|
|
|
extensionPath = ".${extensionDir}/extensions";
|
2018-11-19 16:50:35 +00:00
|
|
|
|
2020-10-12 20:51:12 +00:00
|
|
|
in {
|
2018-11-19 16:50:35 +00:00
|
|
|
options = {
|
|
|
|
programs.vscode = {
|
|
|
|
enable = mkEnableOption "Visual Studio Code";
|
|
|
|
|
2019-07-29 20:39:25 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.vscode;
|
|
|
|
example = literalExample "pkgs.vscodium";
|
|
|
|
description = ''
|
|
|
|
Version of Visual Studio Code to install.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-11-19 16:50:35 +00:00
|
|
|
userSettings = mkOption {
|
2020-11-30 02:54:55 +00:00
|
|
|
type = jsonFormat.type;
|
2020-10-12 20:51:12 +00:00
|
|
|
default = { };
|
2018-11-19 16:50:35 +00:00
|
|
|
example = literalExample ''
|
|
|
|
{
|
|
|
|
"update.channel" = "none";
|
|
|
|
"[nix]"."editor.tabSize" = 2;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
2019-07-07 17:15:47 +00:00
|
|
|
Configuration written to Visual Studio Code's
|
|
|
|
<filename>settings.json</filename>.
|
2018-11-19 16:50:35 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-06-22 18:48:22 +00:00
|
|
|
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.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
2020-10-12 20:51:12 +00:00
|
|
|
default = [ ];
|
2020-06-22 18:48:22 +00:00
|
|
|
example = literalExample ''
|
|
|
|
[
|
|
|
|
{
|
|
|
|
key = "ctrl+c";
|
|
|
|
command = "editor.action.clipboardCopyAction";
|
|
|
|
when = "textInputFocus";
|
|
|
|
}
|
|
|
|
]
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Keybindings written to Visual Studio Code's
|
|
|
|
<filename>keybindings.json</filename>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-11-19 16:50:35 +00:00
|
|
|
extensions = mkOption {
|
|
|
|
type = types.listOf types.package;
|
2020-10-12 20:51:12 +00:00
|
|
|
default = [ ];
|
2019-05-31 19:37:28 +00:00
|
|
|
example = literalExample "[ pkgs.vscode-extensions.bbenoist.Nix ]";
|
2018-11-19 16:50:35 +00:00
|
|
|
description = ''
|
|
|
|
The extensions Visual Studio Code should be started with.
|
|
|
|
These will override but not delete manually installed ones.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2019-07-29 20:39:25 +00:00
|
|
|
home.packages = [ cfg.package ];
|
2018-11-19 16:50:35 +00:00
|
|
|
|
2019-07-29 20:39:25 +00:00
|
|
|
# Adapted from https://discourse.nixos.org/t/vscode-extensions-setup/1801/2
|
2020-10-12 20:51:12 +00:00
|
|
|
home.file = let
|
|
|
|
subDir = "share/vscode/extensions";
|
|
|
|
toPaths = path:
|
|
|
|
# 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 (a: b: a // b) {
|
|
|
|
"${configFilePath}" = mkIf (cfg.userSettings != { }) {
|
2020-11-30 02:54:55 +00:00
|
|
|
source = jsonFormat.generate "vscode-user-settings" cfg.userSettings;
|
2020-10-12 20:51:12 +00:00
|
|
|
};
|
|
|
|
"${keybindingsFilePath}" = mkIf (cfg.keybindings != [ ]) {
|
2020-11-30 02:54:55 +00:00
|
|
|
source = jsonFormat.generate "vscode-keybindings" cfg.keybindings;
|
2020-10-12 20:51:12 +00:00
|
|
|
};
|
|
|
|
} toSymlink;
|
2018-11-19 16:50:35 +00:00
|
|
|
};
|
|
|
|
}
|