Files
Seong Yong-ju 26412a220b vscode: extract mkVscodeModule factory function
Extract the core vscode module logic into a reusable factory function
(mkVscodeModule.nix), following the established mkFirefoxModule pattern.
This is a pure refactor with no behavior change — programs.vscode
retains the same interface.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-03 18:50:49 -05:00

89 lines
1.8 KiB
Nix

package:
{
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;
inherit package;
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}"
'';
}