vscode: support path literals in userSettings
programs.vscode.profiles.<name>.userSettings accepts either JSON settings or a path to a settings.json file. The update-check defaults were merged into userSettings before deciding whether to generate JSON or link a source file, so path values failed when Nix tried to apply // to them. Skip those merges for path-like values and use the shared isPathLike helper for VS Code's source-or-generated JSON options so Nix paths, store path strings, and derivation outputs are handled consistently. Fixes #7726
This commit is contained in:
@@ -22,6 +22,7 @@ let
|
|||||||
optionalString
|
optionalString
|
||||||
types
|
types
|
||||||
;
|
;
|
||||||
|
inherit (lib.hm.strings) isPathLike;
|
||||||
|
|
||||||
moduleName = lib.concatStringsSep "." modulePath;
|
moduleName = lib.concatStringsSep "." modulePath;
|
||||||
|
|
||||||
@@ -60,15 +61,16 @@ let
|
|||||||
|
|
||||||
mergedUserSettings =
|
mergedUserSettings =
|
||||||
userSettings: enableUpdateCheck: enableExtensionUpdateCheck:
|
userSettings: enableUpdateCheck: enableExtensionUpdateCheck:
|
||||||
userSettings
|
if isPathLike userSettings then
|
||||||
// lib.optionalAttrs (enableUpdateCheck == false) {
|
userSettings
|
||||||
"update.mode" = "none";
|
else
|
||||||
}
|
userSettings
|
||||||
// lib.optionalAttrs (enableExtensionUpdateCheck == false) {
|
// lib.optionalAttrs (enableUpdateCheck == false) {
|
||||||
"extensions.autoCheckUpdates" = false;
|
"update.mode" = "none";
|
||||||
};
|
}
|
||||||
|
// lib.optionalAttrs (enableExtensionUpdateCheck == false) {
|
||||||
isPath = p: builtins.isPath p || lib.isStorePath p;
|
"extensions.autoCheckUpdates" = false;
|
||||||
|
};
|
||||||
|
|
||||||
transformMcpServerForVscode = name: server: {
|
transformMcpServerForVscode = name: server: {
|
||||||
inherit name;
|
inherit name;
|
||||||
@@ -372,28 +374,26 @@ in
|
|||||||
home.file = lib.mkMerge (flatten [
|
home.file = lib.mkMerge (flatten [
|
||||||
(mkIf (cfg.argvSettings != { }) {
|
(mkIf (cfg.argvSettings != { }) {
|
||||||
"${argvPath}".source =
|
"${argvPath}".source =
|
||||||
if isPath cfg.argvSettings then
|
if isPathLike cfg.argvSettings then
|
||||||
cfg.argvSettings
|
cfg.argvSettings
|
||||||
else
|
else
|
||||||
jsonFormat.generate "vscode-argv" cfg.argvSettings;
|
jsonFormat.generate "vscode-argv" cfg.argvSettings;
|
||||||
})
|
})
|
||||||
|
|
||||||
(mapAttrsToList (n: v: [
|
(mapAttrsToList (n: v: [
|
||||||
(mkIf ((mergedUserSettings v.userSettings v.enableUpdateCheck v.enableExtensionUpdateCheck) != { })
|
(
|
||||||
{
|
let
|
||||||
|
merged = mergedUserSettings v.userSettings v.enableUpdateCheck v.enableExtensionUpdateCheck;
|
||||||
|
in
|
||||||
|
mkIf (merged != { }) {
|
||||||
"${configFilePath n}".source =
|
"${configFilePath n}".source =
|
||||||
if isPath v.userSettings then
|
if isPathLike merged then merged else jsonFormat.generate "vscode-user-settings" merged;
|
||||||
v.userSettings
|
|
||||||
else
|
|
||||||
jsonFormat.generate "vscode-user-settings" (
|
|
||||||
mergedUserSettings v.userSettings v.enableUpdateCheck v.enableExtensionUpdateCheck
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
(mkIf (v.userTasks != { }) {
|
(mkIf (v.userTasks != { }) {
|
||||||
"${tasksFilePath n}".source =
|
"${tasksFilePath n}".source =
|
||||||
if isPath v.userTasks then v.userTasks else jsonFormat.generate "vscode-user-tasks" v.userTasks;
|
if isPathLike v.userTasks then v.userTasks else jsonFormat.generate "vscode-user-tasks" v.userTasks;
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf
|
(mkIf
|
||||||
@@ -403,7 +403,7 @@ in
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
"${mcpFilePath n}".source =
|
"${mcpFilePath n}".source =
|
||||||
if isPath v.userMcp then
|
if isPathLike v.userMcp then
|
||||||
v.userMcp
|
v.userMcp
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
@@ -424,7 +424,7 @@ in
|
|||||||
|
|
||||||
(mkIf (v.keybindings != [ ]) {
|
(mkIf (v.keybindings != [ ]) {
|
||||||
"${keybindingsFilePath n}".source =
|
"${keybindingsFilePath n}".source =
|
||||||
if isPath v.keybindings then
|
if isPathLike v.keybindings then
|
||||||
v.keybindings
|
v.keybindings
|
||||||
else
|
else
|
||||||
jsonFormat.generate "vscode-keybindings" (map (lib.filterAttrs (_: v: v != null)) v.keybindings);
|
jsonFormat.generate "vscode-keybindings" (map (lib.filterAttrs (_: v: v != null)) v.keybindings);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ let
|
|||||||
mcp-integration = import ./mcp-integration.nix;
|
mcp-integration = import ./mcp-integration.nix;
|
||||||
mcp-integration-with-override = import ./mcp-integration-with-override.nix;
|
mcp-integration-with-override = import ./mcp-integration-with-override.nix;
|
||||||
update-checks = import ./update-checks.nix;
|
update-checks = import ./update-checks.nix;
|
||||||
|
path-literal = import ./path-literal.nix;
|
||||||
snippets = import ./snippets.nix;
|
snippets = import ./snippets.nix;
|
||||||
null-package = import ./null-package.nix;
|
null-package = import ./null-package.nix;
|
||||||
fork-package-warning = import ./fork-package-warning.nix;
|
fork-package-warning = import ./fork-package-warning.nix;
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"editor.fontSize": 18
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package:
|
||||||
|
|
||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
|
let
|
||||||
|
settingsPath =
|
||||||
|
if pkgs.stdenv.hostPlatform.isDarwin then
|
||||||
|
"Library/Application Support/Code/User/settings.json"
|
||||||
|
else
|
||||||
|
".config/Code/User/settings.json";
|
||||||
|
in
|
||||||
|
|
||||||
|
{
|
||||||
|
programs.vscode = {
|
||||||
|
enable = true;
|
||||||
|
inherit package;
|
||||||
|
profiles = {
|
||||||
|
default = {
|
||||||
|
userSettings = ./path-literal-settings.json;
|
||||||
|
enableUpdateCheck = false;
|
||||||
|
enableExtensionUpdateCheck = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
assertFileExists "home-files/${settingsPath}"
|
||||||
|
assertFileContent "home-files/${settingsPath}" "${./path-literal-settings.json}"
|
||||||
|
'';
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user