1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-21 17:59:39 +01:00
home-manager/tests/modules/programs/vscode/tasks.nix
Jonathan Bouchard b022c9e3b8
vscode: allow specifying paths for VSCode JSON settings (#7055)
Enables users to provide paths to JSON files for VS Code settings,
tasks, and keybindings. This allows for more flexible configuration
management and reuse of existing configuration files instead of using inline configurations.
2025-05-15 13:32:46 -05:00

86 lines
1.9 KiB
Nix

{ pkgs, lib, ... }:
let
tasksFilePath =
name:
if pkgs.stdenv.hostPlatform.isDarwin then
"Library/Application Support/Code/User/${
lib.optionalString (name != "default") "profiles/${name}/"
}tasks.json"
else
".config/Code/User/${lib.optionalString (name != "default") "profiles/${name}/"}tasks.json";
content = ''
{
// Comments should be preserved
"tasks": [
{
"command": "hello",
"label": "Hello task",
"type": "shell"
},
{
"command": "world",
"label": "World task",
"type": "shell"
}
],
"version": "2.0.0"
}
'';
tasks = {
version = "2.0.0";
tasks = [
{
type = "shell";
label = "Hello task";
command = "hello";
}
];
};
customTasksPath = pkgs.writeText "custom.json" content;
expectedTasks = pkgs.writeText "tasks-expected.json" ''
{
"tasks": [
{
"command": "hello",
"label": "Hello task",
"type": "shell"
}
],
"version": "2.0.0"
}
'';
expectedCustomTasks = pkgs.writeText "custom-expected.json" content;
in
{
programs.vscode = {
enable = true;
package = pkgs.writeScriptBin "vscode" "" // {
pname = "vscode";
version = "1.75.0";
};
profiles = {
default.userTasks = tasks;
test.userTasks = tasks;
custom.userTasks = customTasksPath;
};
};
nmt.script = ''
assertFileExists "home-files/${tasksFilePath "default"}"
assertFileContent "home-files/${tasksFilePath "default"}" "${expectedTasks}"
assertFileExists "home-files/${tasksFilePath "test"}"
assertFileContent "home-files/${tasksFilePath "test"}" "${expectedTasks}"
assertFileExists "home-files/${tasksFilePath "custom"}"
assertFileContent "home-files/${tasksFilePath "custom"}" "${expectedCustomTasks}"
'';
}