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 ]";
|
example = literalExpression "[ pkgs.vscode-extensions.bbenoist.Nix ]";
|
||||||
description = ''
|
description = ''
|
||||||
The extensions Visual Studio Code should be started with.
|
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 {
|
config = mkIf cfg.enable {
|
||||||
home.packages = [ cfg.package ];
|
home.packages = [ cfg.package ];
|
||||||
|
|
||||||
# Adapted from https://discourse.nixos.org/t/vscode-extensions-setup/1801/2
|
home.file = mkMerge [
|
||||||
home.file = let
|
(mkIf (cfg.userSettings != { }) {
|
||||||
subDir = "share/vscode/extensions";
|
"${configFilePath}".source =
|
||||||
toPaths = ext:
|
jsonFormat.generate "vscode-user-settings" cfg.userSettings;
|
||||||
# Links every dir in ext to the extension path.
|
})
|
||||||
map (k: { "${extensionPath}/${k}".source = "${ext}/${subDir}/${k}"; })
|
(mkIf (cfg.keybindings != { })
|
||||||
(if ext ? vscodeExtUniqueId then
|
(let dropNullFields = filterAttrs (_: v: v != null);
|
||||||
[ ext.vscodeExtUniqueId ]
|
in {
|
||||||
else
|
"${keybindingsFilePath}".source =
|
||||||
builtins.attrNames (builtins.readDir (ext + "/${subDir}")));
|
jsonFormat.generate "vscode-keybindings"
|
||||||
toSymlink = concatMap toPaths cfg.extensions;
|
(map dropNullFields cfg.keybindings);
|
||||||
dropNullFields = filterAttrs (_: v: v != null);
|
}))
|
||||||
in foldr (a: b: a // b) {
|
(mkIf (cfg.extensions != [ ]) (let
|
||||||
"${configFilePath}" = mkIf (cfg.userSettings != { }) {
|
combinedExtensionsDrv = pkgs.buildEnv {
|
||||||
source = jsonFormat.generate "vscode-user-settings" cfg.userSettings;
|
name = "vscode-extensions";
|
||||||
};
|
paths = cfg.extensions;
|
||||||
"${keybindingsFilePath}" = mkIf (cfg.keybindings != [ ]) {
|
};
|
||||||
source = jsonFormat.generate "vscode-keybindings"
|
|
||||||
(map dropNullFields cfg.keybindings);
|
extensionsFolder = "${combinedExtensionsDrv}/share/vscode/extensions";
|
||||||
};
|
|
||||||
} toSymlink;
|
# 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