Files
nixos-config/modules/user/helix.nix
T

133 lines
3.5 KiB
Nix
Raw Normal View History

2026-07-06 07:46:18 +03:00
{ inputs, pkgs, ... }: let
helixSteel =
inputs.helix-steel.packages.${pkgs.system}.default.overrideAttrs (old: {
cargoBuildFlags = (old.cargoBuildFlags or []) ++ [
"--features"
"steel,git"
];
});
comment-headers = pkgs.fetchurl {
url = "https://github.com/codingvivi/comment-dividers.hx/raw/refs/heads/main/comment_headers.scm";
name = "comment_headers.scm";
hash = "sha256-ohgn6DFJl0rdRJuri6Frs/uUlUsPxMvPHDuw4FS3qEE=";
};
patched-comment-headers = pkgs.runCommand "comment_headers.scm" { } ''
install -m 0644 ${comment-headers} "$out"
${pkgs.python3}/bin/python3 - <<'PY'
from pathlib import Path
import os
import sys
p = Path(os.environ["out"])
s = p.read_text()
start_marker = "(define (get-block-delims)"
end_marker = "(define (delete_till_first_nonwhitespace!)"
try:
start = s.index(start_marker)
end = s.index(end_marker, start)
except ValueError as e:
sys.exit(f"failed to find function markers: {e}")
new_get_block_delims = """(define (get-block-delims)
(helix.static.open_above)
(helix.static.insert_string "test_string")
(helix.static.normal_mode)
(helix.static.extend_to_line_bounds)
(helix.static.trim_selections)
(helix.static.toggle_comments)
(let* ([commented-test-string (helix.static.current-highlighted-text!)]
[strings-without-whitespace (split-whitespace commented-test-string)])
(delete-line-noyank!)
(cond
[(and (> (length strings-without-whitespace) 1)
(equal? (last strings-without-whitespace) "test_string"))
(list (first strings-without-whitespace) "")]
[(> (length strings-without-whitespace) 2)
(list (first strings-without-whitespace) (last strings-without-whitespace))]
[else
(list "" "")])))
"""
s = s[:start] + new_get_block_delims + s[end:]
old = "(make-line line-length fill-pattern #f padding-pattern)"
new = "(make-line line-length \"\" fill-pattern padding-pattern)"
if old not in s:
sys.exit("failed to find insert-divider make-line call")
s = s.replace(old, new)
p.write_text(s)
PY
'';
in {
2024-11-24 17:26:08 +03:00
programs.helix = {
enable = true;
2026-07-06 07:46:18 +03:00
package = helixSteel;
2024-11-24 17:26:08 +03:00
defaultEditor = true;
settings = {
# theme = "catppuccin-mocha";
editor = {
2025-12-06 20:41:14 +03:00
rulers = [ 81 ];
2025-01-31 19:45:16 +03:00
insert-final-newline = false;
2025-12-06 20:41:14 +03:00
indent-guides.render = true;
2024-11-24 17:26:08 +03:00
whitespace.render = {
space = "all";
tab = "all";
nbsp = "none";
nnbsp = "none";
newline = "none";
};
2025-12-06 20:41:14 +03:00
cursor-shape = {
normal = "block";
insert = "bar";
select = "underline";
};
2024-11-24 17:26:08 +03:00
};
2026-07-06 07:46:18 +03:00
keys.normal = {
space.C-c = {
h = ":comment-h1";
j = ":comment-h2";
k = ":comment-h3";
d = ":comment-divider";
};
};
2024-11-24 17:26:08 +03:00
};
};
2026-07-06 07:46:18 +03:00
xdg.configFile = {
"helix/cogs/comment_headers.scm".source = patched-comment-headers;
"helix/helix.scm".text = ''
(require (prefix-in div. "cogs/comment_headers.scm"))
(provide comment-h1 comment-h2 comment-h3 comment-divider)
(define (comment-h1)
(div.insert-h1!))
(define (comment-h2)
(div.insert-h2!))
(define (comment-h3)
(div.insert-h3!))
(define (comment-divider)
(div.insert-divider! 80 "~"))
'';
"helix/init.scm".text = ''
;; Steel init file
'';
};
2024-11-24 17:26:08 +03:00
}