mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
zed-editor: respect user interactivity with settings and keymaps (#6993)
Merges frozen config from HM into dirty config. Fixes https://github.com/nix-community/home-manager/issues/6835
This commit is contained in:
parent
de8463dd3e
commit
0ee810c839
4 changed files with 184 additions and 47 deletions
|
|
@ -14,6 +14,16 @@ let
|
||||||
|
|
||||||
cfg = config.programs.zed-editor;
|
cfg = config.programs.zed-editor;
|
||||||
jsonFormat = pkgs.formats.json { };
|
jsonFormat = pkgs.formats.json { };
|
||||||
|
impureConfigMerger = empty: jqOperation: path: staticSettings: ''
|
||||||
|
mkdir -p $(dirname ${lib.escapeShellArg path})
|
||||||
|
if [ ! -e ${lib.escapeShellArg path} ]; then
|
||||||
|
# No file? Create it
|
||||||
|
echo ${lib.escapeShellArg empty} > ${lib.escapeShellArg path}
|
||||||
|
fi
|
||||||
|
config="$(${pkgs.jq}/bin/jq -s ${lib.escapeShellArg jqOperation} ${lib.escapeShellArg path} ${lib.escapeShellArg staticSettings})"
|
||||||
|
printf '%s\n' "$config" > ${lib.escapeShellArg path}
|
||||||
|
unset config
|
||||||
|
'';
|
||||||
|
|
||||||
mergedSettings =
|
mergedSettings =
|
||||||
cfg.userSettings
|
cfg.userSettings
|
||||||
|
|
@ -155,34 +165,31 @@ in
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
xdg.configFile =
|
home.activation = {
|
||||||
lib.attrsets.unionOfDisjoint
|
zedSettingsActivation = lib.hm.dag.entryAfter [ "linkGeneration" ] (
|
||||||
{
|
impureConfigMerger "{}" ".[0] * .[1]" "${config.xdg.configHome}/zed/settings.json" (
|
||||||
"zed/settings.json" = (
|
jsonFormat.generate "zed-user-settings" mergedSettings
|
||||||
mkIf (mergedSettings != { }) {
|
)
|
||||||
source = jsonFormat.generate "zed-user-settings" mergedSettings;
|
);
|
||||||
}
|
zedKeymapActivation = lib.hm.dag.entryAfter [ "linkGeneration" ] (
|
||||||
);
|
impureConfigMerger "[]"
|
||||||
|
".[0] + .[1] | group_by(.context) | map(reduce .[] as $item ({}; . * $item))"
|
||||||
|
"${config.xdg.configHome}/zed/keymap.json"
|
||||||
|
(jsonFormat.generate "zed-user-keymaps" cfg.userKeymaps)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
"zed/keymap.json" = (
|
xdg.configFile = lib.mapAttrs' (
|
||||||
mkIf (cfg.userKeymaps != { }) {
|
n: v:
|
||||||
source = jsonFormat.generate "zed-user-keymaps" cfg.userKeymaps;
|
lib.nameValuePair "zed/themes/${n}.json" {
|
||||||
}
|
source =
|
||||||
);
|
if lib.isString v then
|
||||||
}
|
pkgs.writeText "zed-theme-${n}" v
|
||||||
(
|
else if builtins.isPath v || lib.isStorePath v then
|
||||||
lib.mapAttrs' (
|
v
|
||||||
n: v:
|
else
|
||||||
lib.nameValuePair "zed/themes/${n}.json" {
|
jsonFormat.generate "zed-theme-${n}" v;
|
||||||
source =
|
}
|
||||||
if lib.isString v then
|
) cfg.themes;
|
||||||
pkgs.writeText "zed-theme-${n}" v
|
|
||||||
else if builtins.isPath v || lib.isStorePath v then
|
|
||||||
v
|
|
||||||
else
|
|
||||||
jsonFormat.generate "zed-theme-${n}" v;
|
|
||||||
}
|
|
||||||
) cfg.themes
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,9 @@
|
||||||
{ config, ... }:
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
{
|
{
|
||||||
programs.zed-editor = {
|
programs.zed-editor = {
|
||||||
|
|
@ -11,20 +16,54 @@
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
home.homeDirectory = lib.mkForce "/@TMPDIR@/hm-user";
|
||||||
|
|
||||||
nmt.script =
|
nmt.script =
|
||||||
let
|
let
|
||||||
|
preexistingSettings = builtins.toFile "preexisting.json" ''
|
||||||
|
{
|
||||||
|
"auto_install_extensions": {
|
||||||
|
"python": true,
|
||||||
|
"javascript": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
|
||||||
expectedContent = builtins.toFile "expected.json" ''
|
expectedContent = builtins.toFile "expected.json" ''
|
||||||
{
|
{
|
||||||
"auto_install_extensions": {
|
"auto_install_extensions": {
|
||||||
|
"python": true,
|
||||||
|
"javascript": true,
|
||||||
"html": true,
|
"html": true,
|
||||||
"swift": true,
|
"swift": true,
|
||||||
"xy-zed": true
|
"xy-zed": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
settingsPath = ".config/zed/settings.json";
|
||||||
|
|
||||||
|
activationScript = pkgs.writeScript "activation" config.home.activation.zedSettingsActivation.data;
|
||||||
in
|
in
|
||||||
''
|
''
|
||||||
assertFileExists "home-files/.config/zed/settings.json"
|
export HOME=$TMPDIR/hm-user
|
||||||
assertFileContent "home-files/.config/zed/settings.json" "${expectedContent}"
|
|
||||||
|
# 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}"
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
# Test custom keymap functionality
|
{
|
||||||
{ config, ... }:
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
{
|
{
|
||||||
programs.zed-editor = {
|
programs.zed-editor = {
|
||||||
|
|
@ -20,28 +24,78 @@
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
home.homeDirectory = lib.mkForce "/@TMPDIR@/hm-user";
|
||||||
|
|
||||||
nmt.script =
|
nmt.script =
|
||||||
let
|
let
|
||||||
expectedContent = builtins.toFile "expected.json" ''
|
preexistingKeymaps = builtins.toFile "preexisting.json" ''
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"bindings": {
|
"bindings": {
|
||||||
"up": "menu::SelectPrev"
|
"down": "menu::SelectNext"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"bindings": {
|
"bindings": {
|
||||||
"escape": "editor::Cancel"
|
"down": "select"
|
||||||
|
},
|
||||||
|
"context": "Terminal"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bindings": {
|
||||||
|
"enter": "newline"
|
||||||
},
|
},
|
||||||
"context": "Editor"
|
"context": "Editor"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
expectedContent = builtins.toFile "expected.json" ''
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"bindings": {
|
||||||
|
"down": "menu::SelectNext",
|
||||||
|
"up": "menu::SelectPrev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bindings": {
|
||||||
|
"enter": "newline",
|
||||||
|
"escape": "editor::Cancel"
|
||||||
|
},
|
||||||
|
"context": "Editor"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bindings": {
|
||||||
|
"down": "select"
|
||||||
|
},
|
||||||
|
"context": "Terminal"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
'';
|
||||||
|
|
||||||
keymapPath = ".config/zed/keymap.json";
|
keymapPath = ".config/zed/keymap.json";
|
||||||
|
activationScript = pkgs.writeScript "activation" config.home.activation.zedKeymapActivation.data;
|
||||||
in
|
in
|
||||||
''
|
''
|
||||||
assertFileExists "home-files/${keymapPath}"
|
export HOME=$TMPDIR/hm-user
|
||||||
assertFileContent "home-files/${keymapPath}" "${expectedContent}"
|
|
||||||
|
# Simulate preexisting keymaps
|
||||||
|
mkdir -p $HOME/.config/zed
|
||||||
|
cat ${preexistingKeymaps} > $HOME/${keymapPath}
|
||||||
|
|
||||||
|
# Run the activation script
|
||||||
|
substitute ${activationScript} $TMPDIR/activate --subst-var TMPDIR
|
||||||
|
chmod +x $TMPDIR/activate
|
||||||
|
$TMPDIR/activate
|
||||||
|
|
||||||
|
# Validate the merged keymaps
|
||||||
|
assertFileExists "$HOME/${keymapPath}"
|
||||||
|
assertFileContent "$HOME/${keymapPath}" "${expectedContent}"
|
||||||
|
|
||||||
|
# Test idempotency
|
||||||
|
$TMPDIR/activate
|
||||||
|
assertFileExists "$HOME/${keymapPath}"
|
||||||
|
assertFileContent "$HOME/${keymapPath}" "${expectedContent}"
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
# Test custom keymap functionality
|
# Test custom keymap functionality
|
||||||
{ config, ... }:
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
{
|
{
|
||||||
programs.zed-editor = {
|
programs.zed-editor = {
|
||||||
|
|
@ -16,24 +21,56 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
home.homeDirectory = lib.mkForce "/@TMPDIR@/hm-user";
|
||||||
|
|
||||||
nmt.script =
|
nmt.script =
|
||||||
let
|
let
|
||||||
|
preexistingSettings = builtins.toFile "preexisting.json" ''
|
||||||
|
{
|
||||||
|
"theme": "Default",
|
||||||
|
"features": {
|
||||||
|
"copilot": true,
|
||||||
|
"ai_assist": true
|
||||||
|
},
|
||||||
|
"vim_mode": true
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
|
||||||
expectedContent = builtins.toFile "expected.json" ''
|
expectedContent = builtins.toFile "expected.json" ''
|
||||||
{
|
{
|
||||||
"buffer_font_size": 16,
|
|
||||||
"features": {
|
|
||||||
"copilot": false
|
|
||||||
},
|
|
||||||
"theme": "XY-Zed",
|
"theme": "XY-Zed",
|
||||||
"ui_font_size": 16,
|
"features": {
|
||||||
"vim_mode": false
|
"copilot": false,
|
||||||
|
"ai_assist": true
|
||||||
|
},
|
||||||
|
"vim_mode": false,
|
||||||
|
"buffer_font_size": 16,
|
||||||
|
"ui_font_size": 16
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
settingsPath = ".config/zed/settings.json";
|
settingsPath = ".config/zed/settings.json";
|
||||||
|
activationScript = pkgs.writeScript "activation" config.home.activation.zedSettingsActivation.data;
|
||||||
in
|
in
|
||||||
''
|
''
|
||||||
assertFileExists "home-files/${settingsPath}"
|
export HOME=$TMPDIR/hm-user
|
||||||
assertFileContent "home-files/${settingsPath}" "${expectedContent}"
|
|
||||||
|
# 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}"
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue