# SPDX-FileCopyrightText: 2025 Ethan Reece # # SPDX-License-Identifier: LGPL-3.0-or-later { module-name, ... }: { flake-parts-lib, lib, ... }: { imports = [ ../../base ]; options.perSystem = flake-parts-lib.mkPerSystemOption ( { config, pkgs, system, ... }: { options.editors.${module-name} = { enable = lib.mkEnableOption "Helix"; # https://github.com/helix-editor/helix/blob/master/languages.toml # https://helix-editor.vercel.app/reference/formatters # https://docs.helix-editor.com/lang-support.html # https://docs.helix-editor.com/languages.html languages = lib.mkOption { description = '' Configuration for Helix `languages.toml`. ''; # type = types.attrs; type = lib.types.submodule { options = { language = lib.mkOption { description = '' `language` in `languages.toml`. ''; type = lib.types.listOf lib.types.attrs; default = [ ]; }; language-server = lib.mkOption { description = '' `language-server` in `languages.toml`. ''; type = lib.types.attrs; default = { }; }; }; }; default = { }; }; }; config = let tomlFormatter = pkgs.formats.toml { }; helix = rec { languages = { name = "languages.toml"; }; directory = { name = ".helix"; }; mkHelixDir = hx-config: pkgs.linkFarm directory.name [ { name = languages.name; path = tomlFormatter.generate languages.name hx-config.languages; } ]; mkHelixPackage = hx-config: let dir = mkHelixDir hx-config; in pkgs.writers.writeNuBin "hx" '' def --wrapped main [...args] { let git_root = (^"${pkgs.git}/bin/git" rev-parse --show-toplevel | str trim) ^"${pkgs.uutils-coreutils-noprefix}/bin/ln" -fsn ${dir} $"($git_root)/${directory.name}" ^"${pkgs.helix}/bin/hx" ...$args rm -rf $"($git_root)/${directory.name}" } ''; package = mkHelixPackage config.editors.${module-name}; }; in { _module.args.mkHelixPackage = helix.mkHelixPackage; devshells.default = lib.mkIf config.editors.${module-name}.enable { commands = [ { help = " generate Helix grammars"; name = "helix-grammars"; command = "${helix.package}/bin/hx --grammar fetch && hx --grammar build"; category = "󰤀 Helix"; } ]; packages = [ helix.package ]; }; }; } ); }