Skip to content

Commit

Permalink
feat: helix - add fennel language, formatter, highlight etc
Browse files Browse the repository at this point in the history
  • Loading branch information
johnae committed Sep 11, 2024
1 parent aba8cb8 commit 828d5d7
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 7 deletions.
3 changes: 3 additions & 0 deletions devenv/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ in {
agenix
age-plugin-yubikey
alejandra
fennel
fennel-ls
fnlfmt
hcloud
installTestVM
just
Expand Down
48 changes: 48 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 14 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
nixConfig = {
extra-experimental-features = "nix-command flakes";
extra-substituters = [
"https://nix-community.cachix.org"
"https://insane.cachix.org"
"https://cache.flox.dev"
"https://cachix.cachix.org"
"https://hyprland.cachix.org"
"https://cache.flox.dev"
"https://insane.cachix.org"
"https://nix-community.cachix.org"
];

extra-trusted-public-keys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
"insane.cachix.org-1:cLCCoYQKkmEb/M88UIssfg2FiSDUL4PUjYj9tdo4P8o="
"cachix.cachix.org-1:eWNHQldwUO7G2VkjpnjDbWwy4KQ/HNxht7H4SSoMckM="
"hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc="
"flox-cache-public-1:7F4OyH7ZCnFhcze3fJdfyXYLQw/aV7GEed86nQ7IsOs="
"hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc="
"insane.cachix.org-1:cLCCoYQKkmEb/M88UIssfg2FiSDUL4PUjYj9tdo4P8o="
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
];
};

Expand Down Expand Up @@ -45,6 +46,8 @@
devenv.url = "github:cachix/devenv";
disko.inputs.nixpkgs.follows = "nixpkgs";
disko.url = "github:nix-community/disko";
fennel-tree-sitter.flake = false;
fennel-tree-sitter.url = "github:TravonteD/tree-sitter-fennel/1.1.0";
fenix.inputs.nixpkgs.follows = "nixpkgs";
fenix.url = "github:nix-community/fenix";
flake-compat.flake = false;
Expand All @@ -53,6 +56,11 @@
flake-utils.inputs.systems.follows = "systems";
fluxcd-install.flake = false;
fluxcd-install.url = "https://github.com/fluxcd/flux2/releases/download/v2.3.0/install.yaml"; # gh-release-update
helix-editor.url = "github:helix-editor/helix";
helix-editor.inputs.nixpkgs.follows = "nixpkgs";
helix-editor.inputs.flake-utils.follows = "flake-utils";
helix-editor.inputs.rust-overlay.follows = "rust-overlay";
helix-editor.inputs.crane.follows = "crane";
hetzner-csi-driver.flake = false;
hetzner-csi-driver.url = "https://raw.githubusercontent.com/hetznercloud/csi-driver/v2.9.0/deploy/kubernetes/hcloud-csi.yml"; # gh-release-update
home-manager.inputs.nixpkgs.follows = "nixpkgs";
Expand Down
51 changes: 51 additions & 0 deletions flake/packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,57 @@
boot.kernelPackages = lib.mkForce pkgs.linuxPackages_latest;
}
];
helix-latest = inputs.helix-editor.packages.${system}.default.override {
grammarOverlays = [
(final: prev: {
fennel = pkgs.stdenv.mkDerivation {
pname = "helix-tree-sitter-fennel";
version = inputs.fennel-tree-sitter.rev;
src = inputs.fennel-tree-sitter;
sourceRoot = "source";
dontConfigure = true;
FLAGS = [
"-Isrc"
"-g"
"-O3"
"-fPIC"
"-fno-exceptions"
"-Wl,-z,relro,-z,now"
];
NAME = "fennel";
buildPhase = ''
runHook preBuild
if [[ -e src/scanner.cc ]]; then
$CXX -c src/scanner.cc -o scanner.o $FLAGS
elif [[ -e src/scanner.c ]]; then
$CC -c src/scanner.c -o scanner.o $FLAGS
fi
$CC -c src/parser.c -o parser.o $FLAGS
$CXX -shared -o $NAME.so *.o
ls -al
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir $out
mv $NAME.so $out/
runHook postInstall
'';

# Strip failed on darwin: strip: error: symbols referenced by indirect symbol table entries that can't be stripped
fixupPhase = lib.optionalString pkgs.stdenv.isLinux ''
runHook preFixup
$STRIP $out/$NAME.so
runHook postFixup
'';
};
})
];
};
zjstatus = inputs.zjstatus.packages.${system}.default;
zwift = inputs.zwift.packages.${system}.default;
persway = inputs.persway.packages.${system}.default;
Expand Down
103 changes: 102 additions & 1 deletion users/profiles/helix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,88 @@
OPENROUTER_API_KEY="$(cat /run/agenix/openrouter-lsp-ai)"
export OPENROUTER_API_KEY
fi
exec ${pkgs.helix}/bin/hx "''$@"
exec ${pkgs.helix-latest}/bin/hx "''$@"
'';
};
in {
xdg.configFile."helix/runtime/queries/fennel/highlights.scm".source = pkgs.writeText "fennel-highlights.scm" ''
(comment) @comment
[ "(" ")" "{" "}" "[" "]" ] @punctuation.bracket
[ ":" ":until" "&" "&as" "?" ] @punctuation.special
(nil) @constant.builtin
(vararg) @punctuation.special
(boolean) @constant.builtin.boolean
(number) @constant.numeric
(string) @string
(escape_sequence) @constant.character.escape
((symbol) @variable.builtin
(#match? @variable.builtin "^[$]"))
(binding) @symbol
[ "fn" "lambda" "hashfn" "#" ] @keyword.function
(fn name: [
(symbol) @function
(multi_symbol (symbol) @function .)
])
(lambda name: [
(symbol) @function
(multi_symbol (symbol) @function .)
])
(multi_symbol
"." @punctuation.delimiter
(symbol) @variable.other.member)
(multi_symbol_method
":" @punctuation.delimiter
(symbol) @function.method .)
[ "for" "each" ] @keyword.control.repeat
((symbol) @keyword.control.repeat
(#eq? @keyword.control.repeat
"while"))
[ "match" ] @keyword.control.conditional
((symbol) @keyword.control.conditional
(#match? @keyword.control.conditional "^(if|when)$"))
[ "global" "local" "let" "set" "var" "where" "or" ] @keyword
((symbol) @keyword
(#match? @keyword
"^(comment|do|doc|eval-compiler|lua|macros|quote|tset|values)$"))
((symbol) @keyword.control.import
(#match? @keyword.control.import
"^(require|require-macros|import-macros|include)$"))
[ "collect" "icollect" "accumulate" ] @function.macro
((symbol) @function.macro
(#match? @function.macro
"^(->|->>|-\\?>|-\\?>>|\\?\\.|doto|macro|macrodebug|partial|pick-args|pick-values|with-open)$"))
; Lua builtins
((symbol) @constant.builtin
(#match? @constant.builtin
"^(arg|_ENV|_G|_VERSION)$"))
((symbol) @function.builtin
(#match? @function.builtin
"^(assert|collectgarbage|dofile|error|getmetatable|ipairs|load|loadfile|loadstring|module|next|pairs|pcall|print|rawequal|rawget|rawlen|rawset|require|select|setfenv|setmetatable|tonumber|tostring|type|unpack|warn|xpcall)$"))
(list . (symbol) @function)
(list . (multi_symbol (symbol) @function .))
(symbol) @variable
'';
programs.helix = {
enable = true;
package = helix-ai;
Expand Down Expand Up @@ -80,6 +158,9 @@ in {
};
languages = {
language-server = {
fennel-ls = {
command = "fennel-ls";
};
lsp-ai = {
command = "lsp-ai";
config.memory.file_store = {};
Expand Down Expand Up @@ -357,6 +438,26 @@ in {
name = "yaml";
language-servers = ["yaml-language-server" "lsp-ai"];
}
{
name = "fennel";
scope = "source.fnl";
injection-regex = "(fennel|fnl)";
file-types = ["fnl"];
shebangs = ["fennel"];
roots = [];
comment-token = ";";
indent = {
tab-width = 2;
unit = " ";
};
formatter = {
command = "fnlfmt";
args = ["-"];
};
language-servers = ["fennel-ls" "lsp-ai"];
grammar = "fennel";
auto-format = true;
}
{
name = "lua";
formatter = {
Expand Down

0 comments on commit 828d5d7

Please sign in to comment.