From e30dc02e04ba3209b5e7eeab1d49671176fdc064 Mon Sep 17 00:00:00 2001 From: Ethan Reece Date: Wed, 23 Jul 2025 03:30:59 -0500 Subject: [PATCH] Use different Helix configurations for different Typst endpoints --- README.md | 20 +++++++++++- flake.nix | 7 ---- languages/en-us/default.nix | 8 +++++ languages/typst/default.nix | 64 ++++++++++++++++++++++++------------- 4 files changed, 68 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index bd237f8..abf3900 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,24 @@ individual languages and editors as needed. programming and natural languages. - 🏛 **REUSE**: Simplifies software licensing and checks for errors. -## Usage +## 💡 How it works + +`editors/helix` exposes a set of configuration options for `languages.toml`, +defining the language servers used and the formatters. Although Helix does not +accept `languages.toml` as an argument, it can read from `.helix/languages.toml` +in the project directory, so a wrapper automatically creates this file when +Helix launches. + +Because some configuration options do not allow per-file configurations, a +wrapper script can generate Helix variations with different configurations. For +example, `typst-default` launches a Helix instance where `tinymist` points to +`scratch/typst.typ`, whereas `typst-alt` launches a Helix instance pointing to +`scratch/typst-alt.typ`. + +`flake-parts` allows different components to build onto the configuration +defined in `editors/helix`, so each language in `languages` adds its own +`language` and `language-server` definitions, but only when enabled. + +## 🔧 Usage Use this [template](https://git.sudoer777.dev/me/nix-flake-template). diff --git a/flake.nix b/flake.nix index 2ef5408..c326c0e 100644 --- a/flake.nix +++ b/flake.nix @@ -39,17 +39,10 @@ en-us = { enable = true; dictionary = [ - "Asahi" - "Catppuccin" - "GmbH" "Haug" "Laurenz" - "LLMs" "Mädje" - "Nushell" "Reece" - "SOPS" - "Stylix" ]; vale."{**/*.md,**/scratch/vale.txt}".packages = { RedHat.enable = true; diff --git a/languages/en-us/default.nix b/languages/en-us/default.nix index 71c4600..47034bb 100644 --- a/languages/en-us/default.nix +++ b/languages/en-us/default.nix @@ -216,24 +216,32 @@ { languages.en-us.dictionary = [ "aarch64" + "Asahi" + "Catppuccin" "Devshell" "Dolstra" "Eelco" "FileCopyrightText" "Flake" + "formatters" "https" + "GmbH" "Jujutsu" "LanguageTool" + "LLMs" "LTeX" "Nix" "NixOS" "Nixpkgs" + "Nushell" "qutebrowser" "REUSE" "SnippetBegin" "SnippetCopyrightText" "SnippetEnd" + "SOPS" "SPDX" + "Stylix" "TODO" ]; editors.helix.languages.language-server = { diff --git a/languages/typst/default.nix b/languages/typst/default.nix index 3e6514a..51bf9d6 100644 --- a/languages/typst/default.nix +++ b/languages/typst/default.nix @@ -35,11 +35,30 @@ }; config = lib.mkIf config.languages.typst.enable ( let - tinymistURL = "127.0.0.1:23635"; fonts = pkgs.buildEnv { name = "fonts"; paths = config.languages.typst.fonts; }; + tinymist = { + url = "127.0.0.1:23635"; + config = { + command = "${pkgs.tinymist}/bin/tinymist"; + config = { + preview.background = { + enabled = true; + args = [ + "--data-plane-host=${tinymist.url}" + "--invert-colors=never" + ]; + }; + typstExtraArgs = [ + "--ignore-system-fonts" + "--font-path" + "${fonts}/share/fonts" + ]; + }; + }; + }; in { languages.en-us.dictionary = [ @@ -69,32 +88,32 @@ ]; language-server.tinymist = { command = "${pkgs.tinymist}/bin/tinymist"; - config = { - preview.background = { - enabled = true; - args = [ - "--data-plane-host=${tinymistURL}" - "--invert-colors=never" - ]; - }; - typstExtraArgs = [ - "--ignore-system-fonts" - "--font-path" - "${fonts}/share/fonts" - # "${config.languages.typst.entrypoint}" - ]; - }; + config = tinymist.config; }; }; treefmt.programs.typstyle.enable = true; devshells.default.commands = lib.mkIf config.editors.helix.enable ( lib.mapAttrsToList ( name: value: - # ( let - # helix = { - # config = - # }; + tinymist' = tinymist // { + config = tinymist.config // { + config = tinymist.config.config // { + typstExtraArgs = tinymist.config.config.typstExtraArgs ++ [ value ]; + }; + }; + }; + helix' = { + base = config.editors.helix; + config = helix'.base // { + languages = helix'.base.languages // { + language-server = helix'.base.languages.language-server // { + tinymist = tinymist'.config; + }; + }; + }; + package = mkHelixPackage helix'.config; + }; in { help = "󰌧 launch Typst editing environment for ${name}"; @@ -105,14 +124,13 @@ let git_root = (git rev-parse --show-toplevel | str trim) let file_path = $"($git_root)/${value}" let bg_process = (job spawn { - ${nixGLPkgs.nixgl.nixGLMesa}/bin/nixGLMesa ${pkgs.qutebrowser}/bin/qutebrowser ${tinymistURL} + ${nixGLPkgs.nixgl.nixGLMesa}/bin/nixGLMesa ${pkgs.qutebrowser}/bin/qutebrowser ${tinymist.url} }) - ${pkgs.helix}/bin/hx $file_path + ${helix'.package}/bin/hx $file_path job kill $bg_process ''; } ) config.languages.typst.entrypoints - # ) ); } );