mirror of
https://github.com/nix-community/home-manager
synced 2024-11-23 11:39:46 +01:00
vscode: add package option and link extensions
This commit is contained in:
parent
b1d8c0f9c3
commit
024d1aa227
1 changed files with 39 additions and 8 deletions
|
@ -6,12 +6,22 @@ let
|
|||
|
||||
cfg = config.programs.vscode;
|
||||
|
||||
vscodePname = cfg.package.pname;
|
||||
|
||||
configDir = {
|
||||
"vscode" = "Code";
|
||||
"vscode-insiders" = "Code - Insiders";
|
||||
"vscodium" = "Codium";
|
||||
}.${vscodePname};
|
||||
|
||||
configFilePath =
|
||||
if pkgs.stdenv.hostPlatform.isDarwin then
|
||||
"Library/Application Support/Code/User/settings.json"
|
||||
"Library/Application Support/${configDir}/User/settings.json"
|
||||
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
|
||||
|
||||
{
|
||||
|
@ -19,6 +29,15 @@ in
|
|||
programs.vscode = {
|
||||
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 {
|
||||
type = types.attrs;
|
||||
default = {};
|
||||
|
@ -47,12 +66,24 @@ in
|
|||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
home.packages = [
|
||||
(pkgs.vscode-with-extensions.override {
|
||||
vscodeExtensions = cfg.extensions;
|
||||
})
|
||||
];
|
||||
home.packages = [ cfg.package ];
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue