mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-29 13:41:03 +01:00
fix(zed): support preexisting JSON5 settings (#7317)
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
This commit is contained in:
parent
951f0b30c5
commit
ff31a4677c
3 changed files with 14 additions and 5 deletions
|
|
@ -15,13 +15,16 @@ let
|
|||
|
||||
cfg = config.programs.zed-editor;
|
||||
jsonFormat = pkgs.formats.json { };
|
||||
json5 = pkgs.python3Packages.toPythonApplication pkgs.python3Packages.json5;
|
||||
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})"
|
||||
dynamic="$(${lib.getExe json5} --as-json ${lib.escapeShellArg path})"
|
||||
static="$(cat ${lib.escapeShellArg staticSettings})"
|
||||
config="$(${lib.getExe pkgs.jq} -s ${lib.escapeShellArg jqOperation} --argjson dynamic "$dynamic" --argjson static "$static")"
|
||||
printf '%s\n' "$config" > ${lib.escapeShellArg path}
|
||||
unset config
|
||||
'';
|
||||
|
|
@ -170,7 +173,7 @@ in
|
|||
home.activation = mkMerge [
|
||||
(mkIf (mergedSettings != { }) {
|
||||
zedSettingsActivation = lib.hm.dag.entryAfter [ "linkGeneration" ] (
|
||||
impureConfigMerger "{}" ".[0] * .[1]" "${config.xdg.configHome}/zed/settings.json" (
|
||||
impureConfigMerger "{}" "$dynamic * $static" "${config.xdg.configHome}/zed/settings.json" (
|
||||
jsonFormat.generate "zed-user-settings" mergedSettings
|
||||
)
|
||||
);
|
||||
|
|
@ -178,7 +181,7 @@ in
|
|||
(mkIf (cfg.userKeymaps != [ ]) {
|
||||
zedKeymapActivation = lib.hm.dag.entryAfter [ "linkGeneration" ] (
|
||||
impureConfigMerger "[]"
|
||||
".[0] + .[1] | group_by(.context) | map(reduce .[] as $item ({}; . * $item))"
|
||||
"$dynamic + $static | group_by(.context) | map(reduce .[] as $item ({}; . * $item))"
|
||||
"${config.xdg.configHome}/zed/keymap.json"
|
||||
(jsonFormat.generate "zed-user-keymaps" cfg.userKeymaps)
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue