1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-28 21:21:02 +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:
Jairo Llopis 2025-06-06 03:20:23 +01:00 committed by GitHub
parent de8463dd3e
commit 0ee810c839
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 184 additions and 47 deletions

View file

@ -14,6 +14,16 @@ let
cfg = config.programs.zed-editor;
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 =
cfg.userSettings
@ -155,34 +165,31 @@ in
}
);
xdg.configFile =
lib.attrsets.unionOfDisjoint
{
"zed/settings.json" = (
mkIf (mergedSettings != { }) {
source = jsonFormat.generate "zed-user-settings" mergedSettings;
}
);
home.activation = {
zedSettingsActivation = lib.hm.dag.entryAfter [ "linkGeneration" ] (
impureConfigMerger "{}" ".[0] * .[1]" "${config.xdg.configHome}/zed/settings.json" (
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" = (
mkIf (cfg.userKeymaps != { }) {
source = jsonFormat.generate "zed-user-keymaps" cfg.userKeymaps;
}
);
}
(
lib.mapAttrs' (
n: v:
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
v
else
jsonFormat.generate "zed-theme-${n}" v;
}
) cfg.themes
);
xdg.configFile = lib.mapAttrs' (
n: v:
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
v
else
jsonFormat.generate "zed-theme-${n}" v;
}
) cfg.themes;
};
}