From 024d1aa227978fe2dae2fb3e56bab9a7237c2401 Mon Sep 17 00:00:00 2001 From: Pasquale Date: Mon, 29 Jul 2019 22:39:25 +0200 Subject: [PATCH] vscode: add package option and link extensions --- modules/programs/vscode.nix | 47 ++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/modules/programs/vscode.nix b/modules/programs/vscode.nix index 3a82816f..fdaea0ba 100644 --- a/modules/programs/vscode.nix +++ b/modules/programs/vscode.nix @@ -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; }; }