From 4c5c1e8ba14f1c7475fa31ff11bc1c19cd220974 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Wed, 3 Jun 2026 12:52:59 -0500 Subject: [PATCH] alacritty: fix toml escape generation --- modules/programs/alacritty.nix | 16 ++++++++++++++-- .../programs/alacritty/settings-merging.nix | 5 +++++ .../alacritty/settings-toml-expected.toml | 5 +++++ tests/modules/programs/alacritty/toml-config.nix | 5 +++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/modules/programs/alacritty.nix b/modules/programs/alacritty.nix index 583f269ac..96f157c28 100644 --- a/modules/programs/alacritty.nix +++ b/modules/programs/alacritty.nix @@ -100,8 +100,20 @@ in _finalAttrs: prevAttrs: { buildCommand = lib.concatStringsSep "\n" [ prevAttrs.buildCommand - # TODO: why is this needed? Is there a better way to retain escape sequences? - "substituteInPlace $out --replace-quiet '\\\\' '\\'" + # Nix cannot spell TOML escape sequences like "\u001d" directly: + # "\\u001d" is a literal backslash-u string, while fromJSON creates + # a control character and fails for "\u0000". Normalize both TOML + # generator outputs to the Alacritty escape form: + # chars = "\\u001d" -> chars = "\u001d" + # chars = '\u001d' -> chars = "\u001d" + '' + sed \ + -E \ + -e "s/= \"\\\\\\\\u([0-9a-fA-F]{4})\"\$/= \"\\\\u\1\"/" \ + -e "s/= '\\\\u([0-9a-fA-F]{4})'\$/= \"\\\\u\1\"/" \ + "$out" > "$TMPDIR/alacritty.toml" + cp "$TMPDIR/alacritty.toml" "$out" + '' ]; } ); diff --git a/tests/modules/programs/alacritty/settings-merging.nix b/tests/modules/programs/alacritty/settings-merging.nix index 45cb27264..e697f99a9 100644 --- a/tests/modules/programs/alacritty/settings-merging.nix +++ b/tests/modules/programs/alacritty/settings-merging.nix @@ -15,6 +15,11 @@ mods = "Control"; chars = "\\u000c"; } + { + key = "RBracket"; + mods = "Alt"; + chars = "\\u001d"; + } ]; font = diff --git a/tests/modules/programs/alacritty/settings-toml-expected.toml b/tests/modules/programs/alacritty/settings-toml-expected.toml index 986c92f91..edce8f171 100644 --- a/tests/modules/programs/alacritty/settings-toml-expected.toml +++ b/tests/modules/programs/alacritty/settings-toml-expected.toml @@ -9,6 +9,11 @@ chars = "\u000c" key = "K" mods = "Control" +[[keyboard.bindings]] +chars = "\u001d" +key = "RBracket" +mods = "Alt" + [window.dimensions] columns = 200 lines = 3 diff --git a/tests/modules/programs/alacritty/toml-config.nix b/tests/modules/programs/alacritty/toml-config.nix index 6f531e360..4f6606cc3 100644 --- a/tests/modules/programs/alacritty/toml-config.nix +++ b/tests/modules/programs/alacritty/toml-config.nix @@ -13,6 +13,11 @@ mods = "Control"; chars = "\\u000c"; } + { + key = "RBracket"; + mods = "Alt"; + chars = "\\u001d"; + } ]; font = {