1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 19:46:05 +01:00
home-manager/tests/modules/programs/zed-editor/tasks-empty.nix
Jairo Llopis 13a83d1b65
zed-editor: support tasks (#7493)
Just like other features, they can merge with preexisting JSON5
settings.
2025-07-20 19:14:57 -05:00

69 lines
1.6 KiB
Nix

{
config,
lib,
pkgs,
...
}:
{
programs.zed-editor = {
enable = true;
package = config.lib.test.mkStubPackage { };
userTasks = [
{
label = "Format Code";
command = "nix";
args = [
"fmt"
"$ZED_WORKTREE_ROOT"
];
allow_concurrent_runs = false;
}
];
};
home.homeDirectory = lib.mkForce "/@TMPDIR@/hm-user";
nmt.script =
let
preexistingTasks = builtins.toFile "preexisting.json" "";
expectedContent = builtins.toFile "expected.json" ''
[
{
"allow_concurrent_runs": false,
"args": [
"fmt",
"$ZED_WORKTREE_ROOT"
],
"command": "nix",
"label": "Format Code"
}
]
'';
taskPath = ".config/zed/tasks.json";
activationScript = pkgs.writeScript "activation" config.home.activation.zedTasksActivation.data;
in
''
export HOME=$TMPDIR/hm-user
# Simulate preexisting tasks
mkdir -p $HOME/.config/zed
cat ${preexistingTasks} > $HOME/${taskPath}
# Run the activation script
substitute ${activationScript} $TMPDIR/activate --subst-var TMPDIR
chmod +x $TMPDIR/activate
$TMPDIR/activate
# Validate the merged tasks
assertFileExists "$HOME/${taskPath}"
assertFileContent "$HOME/${taskPath}" "${expectedContent}"
# Test idempotency
$TMPDIR/activate
assertFileExists "$HOME/${taskPath}"
assertFileContent "$HOME/${taskPath}" "${expectedContent}"
'';
}