mirror of
https://github.com/nix-community/home-manager.git
synced 2025-12-02 23:21:02 +01:00
Zed uses JSON5 for settings files. JQ doesn't understand that format and fails if found, when merging with preexisting settings. Here I add a conversion step that converts JSON5 to JSON before handling the contents to JQ. Besides, I changed the arguments in the jq function, so instead of using `[0]` and `[1]`, we now use `$dynamic` and `$static` respectively. This should make scripts more readable. Fixes https://github.com/nix-community/home-manager/issues/7247 Fixes https://github.com/nix-community/home-manager/issues/7226
79 lines
1.9 KiB
Nix
79 lines
1.9 KiB
Nix
# Test custom keymap functionality
|
|
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
|
|
{
|
|
programs.zed-editor = {
|
|
enable = true;
|
|
package = config.lib.test.mkStubPackage { };
|
|
userSettings = {
|
|
theme = "XY-Zed";
|
|
features = {
|
|
copilot = false;
|
|
};
|
|
vim_mode = false;
|
|
ui_font_size = 16;
|
|
buffer_font_size = 16;
|
|
};
|
|
};
|
|
|
|
home.homeDirectory = lib.mkForce "/@TMPDIR@/hm-user";
|
|
|
|
nmt.script =
|
|
let
|
|
preexistingSettings = builtins.toFile "preexisting.json" ''
|
|
{
|
|
// I chose this theme interactively
|
|
"theme": "Default",
|
|
|
|
/* I change AI settings interactively */
|
|
"features": {
|
|
"copilot": true,
|
|
"ai_assist": true
|
|
},
|
|
"vim_mode": true
|
|
}
|
|
'';
|
|
|
|
expectedContent = builtins.toFile "expected.json" ''
|
|
{
|
|
"theme": "XY-Zed",
|
|
"features": {
|
|
"copilot": false,
|
|
"ai_assist": true
|
|
},
|
|
"vim_mode": false,
|
|
"buffer_font_size": 16,
|
|
"ui_font_size": 16
|
|
}
|
|
'';
|
|
|
|
settingsPath = ".config/zed/settings.json";
|
|
activationScript = pkgs.writeScript "activation" config.home.activation.zedSettingsActivation.data;
|
|
in
|
|
''
|
|
export HOME=$TMPDIR/hm-user
|
|
|
|
# Simulate preexisting settings
|
|
mkdir -p $HOME/.config/zed
|
|
cat ${preexistingSettings} > $HOME/${settingsPath}
|
|
|
|
# Run the activation script
|
|
substitute ${activationScript} $TMPDIR/activate --subst-var TMPDIR
|
|
chmod +x $TMPDIR/activate
|
|
$TMPDIR/activate
|
|
|
|
# Validate the merged settings
|
|
assertFileExists "$HOME/${settingsPath}"
|
|
assertFileContent "$HOME/${settingsPath}" "${expectedContent}"
|
|
|
|
# Test idempotency
|
|
$TMPDIR/activate
|
|
assertFileExists "$HOME/${settingsPath}"
|
|
assertFileContent "$HOME/${settingsPath}" "${expectedContent}"
|
|
'';
|
|
}
|