1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-04 18:29:45 +01:00

vscode: add package option and link extensions

This commit is contained in:
Pasquale 2019-07-29 22:39:25 +02:00 committed by Robert Helgesson
parent b1d8c0f9c3
commit 024d1aa227
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89

View file

@ -6,12 +6,22 @@ let
cfg = config.programs.vscode; cfg = config.programs.vscode;
vscodePname = cfg.package.pname;
configDir = {
"vscode" = "Code";
"vscode-insiders" = "Code - Insiders";
"vscodium" = "Codium";
}.${vscodePname};
configFilePath = configFilePath =
if pkgs.stdenv.hostPlatform.isDarwin then if pkgs.stdenv.hostPlatform.isDarwin then
"Library/Application Support/Code/User/settings.json" "Library/Application Support/${configDir}/User/settings.json"
else else
"${config.xdg.configHome}/Code/User/settings.json"; "${config.xdg.configHome}/${configDir}/User/settings.json";
# TODO: On Darwin where are the extensions?
extensionPath = ".${vscodePname}/extensions";
in in
{ {
@ -19,6 +29,15 @@ in
programs.vscode = { programs.vscode = {
enable = mkEnableOption "Visual Studio Code"; enable = mkEnableOption "Visual Studio Code";
package = mkOption {
type = types.package;
default = pkgs.vscode;
example = literalExample "pkgs.vscodium";
description = ''
Version of Visual Studio Code to install.
'';
};
userSettings = mkOption { userSettings = mkOption {
type = types.attrs; type = types.attrs;
default = {}; default = {};
@ -47,12 +66,24 @@ in
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
home.packages = [ home.packages = [ cfg.package ];
(pkgs.vscode-with-extensions.override {
vscodeExtensions = cfg.extensions;
})
];
home.file."${configFilePath}".text = builtins.toJSON cfg.userSettings; # Adapted from https://discourse.nixos.org/t/vscode-extensions-setup/1801/2
home.file =
let
toPaths = p:
# Links every dir in p to the extension path.
mapAttrsToList (k: v:
{
"${extensionPath}/${k}".source = "${p}/${k}";
}) (builtins.readDir p);
toSymlink = concatMap toPaths cfg.extensions;
in
foldr
(a: b: a // b)
{
"${configFilePath}".text = builtins.toJSON cfg.userSettings;
}
toSymlink;
}; };
} }