This repository has been archived on 2025-10-08. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
nixos-config/options/home/editors/helix.nix

171 lines
4.2 KiB
Nix

{
lib,
pkgs,
inputs,
config,
...
}:
let
inherit (lib)
mkIf
mkOption
optional
optionals
mkEnableOption
;
inherit (lib.types) str attrs;
cfg = config.home.editors;
in
{
options.home.editors.helix = {
enable = mkEnableOption "Helix - text editor.";
defaultEditor = mkEnableOption "Make Helix default editor.";
systemArch = mkOption {
type = str;
default = pkgs.system;
description = "System arch for Helix flake package.";
};
keys = mkOption {
type = attrs;
default = { };
description = "Hot keys in Helix editor.";
};
nix.enable = mkEnableOption "Nix lang support in Helix.";
python.enable = mkEnableOption "Python lang support in Helix.";
rust.enable = mkEnableOption "Rust lang support in Helix.";
json.enable = mkEnableOption "JSON support in Helix.";
};
config = mkIf cfg.enable {
programs.helix = 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/"
]
++ optionals cfg.helix.python.enable [
"__pycache__/"
".ruff_cache/"
".venv/"
]
++ optionals cfg.helix.rust.enable [
"target/"
];
languages.language =
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" ];
}
++ 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" ];
}
++ 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"
"-"
];
};
}
++ 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 = mkIf cfg.helix.nix.enable {
command = "${pkgs.nixd}/bin/nixd";
};
rust-analyzer = mkIf cfg.helix.rust.enable {
command = "${pkgs.rust-analyzer}/bin/rust-analyzer";
};
ruff = mkIf cfg.helix.python.enable {
command = "${pkgs.ruff}/bin/ruff";
args = [ "server" ];
config.settings = {
lineLength = 89;
logLevel = "debug";
};
};
vscode-json = mkIf cfg.helix.json.enable {
command = "${pkgs.vscode-langservers-extracted}/bin/vscode-json-language-server";
};
};
};
};
}