From 8596be2dab970b30632c7a1ac96680156bf4fe4a Mon Sep 17 00:00:00 2001 From: ulic-youthlic Date: Wed, 5 Feb 2025 00:07:13 +0800 Subject: [PATCH] modify helix package and add idris tree-sitter integration --- pkgs/default.nix | 2 +- pkgs/{helix.nix => helix/default.nix} | 19 ++++-- pkgs/helix/grammars/default.nix | 94 +++++++++++++++++++++++++++ pkgs/helix/grammars/idris.nix | 6 ++ 4 files changed, 116 insertions(+), 5 deletions(-) rename pkgs/{helix.nix => helix/default.nix} (60%) create mode 100644 pkgs/helix/grammars/default.nix create mode 100644 pkgs/helix/grammars/idris.nix diff --git a/pkgs/default.nix b/pkgs/default.nix index 48ba5af..4407b6d 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -5,7 +5,7 @@ }: { pinentry-selector = pkgs.callPackage ./pinentry-selector.nix { }; - helix = pkgs.callPackage ./helix.nix { inherit inputs; }; + helix = pkgs.callPackage ./helix { inherit inputs; }; juicity = pkgs.callPackage ./juicity.nix { }; } // ( diff --git a/pkgs/helix.nix b/pkgs/helix/default.nix similarity index 60% rename from pkgs/helix.nix rename to pkgs/helix/default.nix index 9f5fa7b..b01dcea 100644 --- a/pkgs/helix.nix +++ b/pkgs/helix/default.nix @@ -3,12 +3,23 @@ pkgs, inputs, ... -}: +}@args: let - helix = inputs.helix.packages."${pkgs.system}".default; + inherit (inputs.helix.packages."${pkgs.system}") helix helix-unwrapped; + helix-core = helix-unwrapped.overrideAttrs { + HELIX_DEFAULT_RUNTIME = "${grammarRuntime}"; + }; + helix-wrapped = (helix.override grammarConfig).passthru.wrapper helix-core; + grammars = import ./grammars args; + grammarOverlays = grammars.overlays; + grammarRuntime = grammars.runtime; + grammarConfig = { + inherit grammarOverlays; + }; runtimeInputs = ( with pkgs; [ + idris2Packages.idris2Lsp lua-language-server bash-language-server hurl @@ -43,8 +54,8 @@ let in pkgs.symlinkJoin { name = "helix-wrapped"; - paths = [ helix ]; - inherit (helix) meta; + paths = [ helix-wrapped ]; + inherit (helix-wrapped) meta; buildInputs = [ pkgs.makeWrapper ]; diff --git a/pkgs/helix/grammars/default.nix b/pkgs/helix/grammars/default.nix new file mode 100644 index 0000000..46ec04b --- /dev/null +++ b/pkgs/helix/grammars/default.nix @@ -0,0 +1,94 @@ +{ lib, pkgs, ... }: +let + inherit (pkgs) stdenv; + buildGrammar = + grammar: + let + source = sources."${grammar.name}"; + in + stdenv.mkDerivation { + pname = "helix-tree-sitter-${grammar.name}"; + version = grammar.rev; + src = source; + sourceRoot = "source"; + + dontConfigue = true; + + FLAGS = [ + "-Isrc" + "-g" + "-O3" + "-fPIC" + "-fno-exceptions" + "-Wl,-z,relro,-z,now" + ]; + + NAME = grammar.name; + + 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 + ''; + + fixupPhase = lib.optionalString stdenv.isLinux '' + runHook preFixup + + $STRIP $out/$NAME.so + + runHook postFixup + ''; + }; + grammars = map (file: import file) grammarFiles; + sources = lib.listToAttrs ( + map (grammar: { + inherit (grammar) name; + value = builtins.fetchTree { + type = "github"; + inherit (grammar) owner repo rev; }; + }) grammars + ); + queries = lib.mapAttrsToList (name: value: '' + mkdir -p $out/queries/${name} + cp ${value}/queries/* $out/queries/${name}/ + '') sources; + runtime = pkgs.runCommand "helix-default-runtime" { } '' + mkdir -p $out + ${builtins.concatStringsSep "\n" queries} + ''; + builtGrammars = lib.listToAttrs ( + map (grammar: { + inherit (grammar) name; + value = buildGrammar grammar; + }) grammars + ); + grammarFiles = [ + ./idris.nix + ]; +in +{ + overlays = [ + (final: prev: lib.filterAttrs (n: v: !(builtins.hasAttr n prev)) builtGrammars) + ]; + inherit runtime; +} diff --git a/pkgs/helix/grammars/idris.nix b/pkgs/helix/grammars/idris.nix new file mode 100644 index 0000000..eb8d149 --- /dev/null +++ b/pkgs/helix/grammars/idris.nix @@ -0,0 +1,6 @@ +{ + name = "idris"; + owner = "kayhide"; + repo = "tree-sitter-idris"; + rev = "c56a25cf57c68ff929356db25505c1cc4c7820f6"; +}