vscode: add package option and link extensions
This commit is contained in:
parent
b1d8c0f9c3
commit
024d1aa227
|
@ -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;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue