mirror of
https://github.com/nix-community/home-manager
synced 2024-11-23 05:03:09 +00:00
vscode: Add immutable extensions dir option (#2613)
This commit is contained in:
parent
a52aed72c8
commit
184b0154f2
1 changed files with 40 additions and 22 deletions
|
@ -115,7 +115,16 @@ in {
|
|||
example = literalExpression "[ pkgs.vscode-extensions.bbenoist.Nix ]";
|
||||
description = ''
|
||||
The extensions Visual Studio Code should be started with.
|
||||
These will override but not delete manually installed ones.
|
||||
'';
|
||||
};
|
||||
|
||||
immutableExtensionsDir = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
example = true;
|
||||
description = ''
|
||||
Whether extensions can be installed or updated manually
|
||||
or by Visual Studio Code.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
@ -124,26 +133,35 @@ in {
|
|||
config = mkIf cfg.enable {
|
||||
home.packages = [ cfg.package ];
|
||||
|
||||
# Adapted from https://discourse.nixos.org/t/vscode-extensions-setup/1801/2
|
||||
home.file = let
|
||||
subDir = "share/vscode/extensions";
|
||||
toPaths = ext:
|
||||
# Links every dir in ext to the extension path.
|
||||
map (k: { "${extensionPath}/${k}".source = "${ext}/${subDir}/${k}"; })
|
||||
(if ext ? vscodeExtUniqueId then
|
||||
[ ext.vscodeExtUniqueId ]
|
||||
else
|
||||
builtins.attrNames (builtins.readDir (ext + "/${subDir}")));
|
||||
toSymlink = concatMap toPaths cfg.extensions;
|
||||
dropNullFields = filterAttrs (_: v: v != null);
|
||||
in foldr (a: b: a // b) {
|
||||
"${configFilePath}" = mkIf (cfg.userSettings != { }) {
|
||||
source = jsonFormat.generate "vscode-user-settings" cfg.userSettings;
|
||||
};
|
||||
"${keybindingsFilePath}" = mkIf (cfg.keybindings != [ ]) {
|
||||
source = jsonFormat.generate "vscode-keybindings"
|
||||
home.file = mkMerge [
|
||||
(mkIf (cfg.userSettings != { }) {
|
||||
"${configFilePath}".source =
|
||||
jsonFormat.generate "vscode-user-settings" cfg.userSettings;
|
||||
})
|
||||
(mkIf (cfg.keybindings != { })
|
||||
(let dropNullFields = filterAttrs (_: v: v != null);
|
||||
in {
|
||||
"${keybindingsFilePath}".source =
|
||||
jsonFormat.generate "vscode-keybindings"
|
||||
(map dropNullFields cfg.keybindings);
|
||||
}))
|
||||
(mkIf (cfg.extensions != [ ]) (let
|
||||
combinedExtensionsDrv = pkgs.buildEnv {
|
||||
name = "vscode-extensions";
|
||||
paths = cfg.extensions;
|
||||
};
|
||||
} toSymlink;
|
||||
|
||||
extensionsFolder = "${combinedExtensionsDrv}/share/vscode/extensions";
|
||||
|
||||
# Adapted from https://discourse.nixos.org/t/vscode-extensions-setup/1801/2
|
||||
addSymlinkToExtension = k: {
|
||||
"${extensionPath}/${k}".source = "${extensionsFolder}/${k}";
|
||||
};
|
||||
extensions = builtins.attrNames (builtins.readDir extensionsFolder);
|
||||
in if cfg.immutableExtensionsDir then {
|
||||
"${extensionPath}".source = extensionsFolder;
|
||||
} else
|
||||
mkMerge (map addSymlinkToExtension extensions)))
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue