2018-11-19 17:50:35 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.vscode;
|
|
|
|
|
2019-07-29 22:39:25 +02:00
|
|
|
vscodePname = cfg.package.pname;
|
|
|
|
|
|
|
|
configDir = {
|
|
|
|
"vscode" = "Code";
|
|
|
|
"vscode-insiders" = "Code - Insiders";
|
2019-11-11 17:50:34 +01:00
|
|
|
"vscodium" = "VSCodium";
|
2019-07-29 22:39:25 +02:00
|
|
|
}.${vscodePname};
|
|
|
|
|
2019-12-06 14:00:28 +01:00
|
|
|
extensionDir = {
|
|
|
|
"vscode" = "vscode";
|
|
|
|
"vscode-insiders" = "vscode-insiders";
|
|
|
|
"vscodium" = "vscode-oss";
|
|
|
|
}.${vscodePname};
|
|
|
|
|
2019-07-07 19:15:47 +02:00
|
|
|
configFilePath =
|
|
|
|
if pkgs.stdenv.hostPlatform.isDarwin then
|
2019-07-29 22:39:25 +02:00
|
|
|
"Library/Application Support/${configDir}/User/settings.json"
|
2019-07-07 19:15:47 +02:00
|
|
|
else
|
2019-07-29 22:39:25 +02:00
|
|
|
"${config.xdg.configHome}/${configDir}/User/settings.json";
|
2019-07-07 19:15:47 +02:00
|
|
|
|
2019-07-29 22:39:25 +02:00
|
|
|
# TODO: On Darwin where are the extensions?
|
2019-12-06 14:00:28 +01:00
|
|
|
extensionPath = ".${extensionDir}/extensions";
|
2018-11-19 17:50:35 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
programs.vscode = {
|
|
|
|
enable = mkEnableOption "Visual Studio Code";
|
|
|
|
|
2019-07-29 22:39:25 +02:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.vscode;
|
|
|
|
example = literalExample "pkgs.vscodium";
|
|
|
|
description = ''
|
|
|
|
Version of Visual Studio Code to install.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-11-19 17:50:35 +01:00
|
|
|
userSettings = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = {};
|
|
|
|
example = literalExample ''
|
|
|
|
{
|
|
|
|
"update.channel" = "none";
|
|
|
|
"[nix]"."editor.tabSize" = 2;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
2019-07-07 19:15:47 +02:00
|
|
|
Configuration written to Visual Studio Code's
|
|
|
|
<filename>settings.json</filename>.
|
2018-11-19 17:50:35 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extensions = mkOption {
|
|
|
|
type = types.listOf types.package;
|
|
|
|
default = [];
|
2019-05-31 21:37:28 +02:00
|
|
|
example = literalExample "[ pkgs.vscode-extensions.bbenoist.Nix ]";
|
2018-11-19 17:50:35 +01: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 22:39:25 +02:00
|
|
|
home.packages = [ cfg.package ];
|
2018-11-19 17:50:35 +01:00
|
|
|
|
2019-07-29 22:39:25 +02:00
|
|
|
# Adapted from https://discourse.nixos.org/t/vscode-extensions-setup/1801/2
|
|
|
|
home.file =
|
|
|
|
let
|
2019-11-11 00:43:42 +01:00
|
|
|
toPaths = path:
|
2020-03-18 06:40:21 +01:00
|
|
|
# Links every dir in path to the extension path.
|
|
|
|
mapAttrsToList (k: v:
|
|
|
|
{
|
|
|
|
"${extensionPath}/${k}".source = "${path}/${k}";
|
|
|
|
}) (builtins.readDir path);
|
2019-07-29 22:39:25 +02:00
|
|
|
toSymlink = concatMap toPaths cfg.extensions;
|
|
|
|
in
|
|
|
|
foldr
|
|
|
|
(a: b: a // b)
|
|
|
|
{
|
2019-11-28 22:01:58 +01:00
|
|
|
"${configFilePath}" =
|
|
|
|
mkIf (cfg.userSettings != {}) {
|
|
|
|
text = builtins.toJSON cfg.userSettings;
|
|
|
|
};
|
2019-07-29 22:39:25 +02:00
|
|
|
}
|
|
|
|
toSymlink;
|
2018-11-19 17:50:35 +01:00
|
|
|
};
|
|
|
|
}
|