{ lib, pkgs, inputs, config, ... }: let cfg = config.home.editors; in { options.home.editors.helix = { enable = lib.mkOption { type = lib.types.bool; default = false; description = "Helix - text editor."; }; defaultEditor = lib.mkOption { type = lib.types.bool; default = false; description = "Make Helix default editor."; }; systemArch = lib.mkOption { type = lib.types.str; default = pkgs.system; description = "System arch for Helix flake package."; }; keys = lib.mkOption { type = lib.types.attrs; default = { }; description = "Hot keys in Helix editor."; }; nix.enable = lib.mkOption { type = lib.types.bool; default = false; description = "Nix lang support in Helix."; }; python.enable = lib.mkOption { type = lib.types.bool; default = false; description = "Python lang support in Helix."; }; rust.enable = lib.mkOption { type = lib.types.bool; default = false; description = "Rust lang support in Helix."; }; json.enable = lib.mkOption { type = lib.types.bool; default = false; description = "JSON support in Helix."; }; }; config = lib.mkIf cfg.enable { programs.helix = lib.mkIf cfg.helix.enable { enable = true; defaultEditor = cfg.helix.defaultEditor; package = inputs.helix.packages.${cfg.helix.systemArch}.helix; settings.editor = { auto-format = true; idle-timeout = 200; mouse = false; scrolloff = 8; middle-click-paste = false; true-color = true; line-number = "relative"; rulers = [ 90 ]; cursorline = true; cursor-shape = { normal = "block"; insert = "bar"; select = "underline"; }; soft-wrap = { enable = true; wrap-indicator = ""; wrap-at-text-width = true; }; lsp = { enable = true; display-messages = true; snippets = true; display-inlay-hints = true; }; file-picker = { hidden = false; git-ignore = false; git-global = true; }; }; settings.keys = cfg.helix.keys; ignores = [ ".git/" ] ++ lib.optionals cfg.helix.python.enable [ "__pycache__/" ".ruff_cache/" ".venv/" ] ++ lib.optionals cfg.helix.rust.enable [ "target/" ]; languages.language = lib.optional cfg.helix.nix.enable { name = "nix"; file-types = [ "nix" ]; auto-format = true; indent = { tab-width = 2; unit = " "; }; formatter.command = "${pkgs.nixfmt-rfc-style}/bin/nixfmt"; language-servers = [ "nixd" ]; } ++ lib.optional cfg.helix.rust.enable { name = "rust"; file-types = [ "rs" ]; auto-format = true; indent = { tab-width = 4; unit = " "; }; formatter.command = "${pkgs.rustfmt}/bin/rustfmt"; language-servers = [ "rust-analyzer" ]; } ++ lib.optional cfg.helix.python.enable { name = "python"; file-types = [ "py" ]; auto-format = true; indent = { tab-width = 4; unit = " "; }; language-servers = [ "ruff" ]; formatter = { command = "${pkgs.black}/bin/black"; args = [ "--quiet" "--line-length=90" "-" ]; }; } ++ lib.optional cfg.helix.json.enable { name = "json"; auto-format = true; language-servers = [ "vscode-json" ]; formatter.command = "${pkgs.vscode-langservers-extracted}/bin/vscode-json-language-server"; }; languages.language-server = { nixd = lib.mkIf cfg.helix.nix.enable { command = "${pkgs.nixd}/bin/nixd"; }; rust-analyzer = lib.mkIf cfg.helix.rust.enable { command = "${pkgs.rust-analyzer}/bin/rust-analyzer"; }; ruff = lib.mkIf cfg.helix.python.enable { command = "${pkgs.ruff}/bin/ruff"; args = [ "server" ]; config.settings = { lineLength = 89; logLevel = "debug"; }; }; vscode-json = lib.mkIf cfg.helix.json.enable { command = "${pkgs.vscode-langservers-extracted}/bin/vscode-json-language-server"; }; }; }; }; }