modify helix package and add idris tree-sitter integration

This commit is contained in:
ulic-youthlic 2025-02-05 00:07:13 +08:00
parent 5fefe07d75
commit 8596be2dab
Signed by: youthlic
GPG key ID: 63E86C3C14A0D721
4 changed files with 116 additions and 5 deletions

View file

@ -5,7 +5,7 @@
}: }:
{ {
pinentry-selector = pkgs.callPackage ./pinentry-selector.nix { }; 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 { }; juicity = pkgs.callPackage ./juicity.nix { };
} }
// ( // (

View file

@ -3,12 +3,23 @@
pkgs, pkgs,
inputs, inputs,
... ...
}: }@args:
let 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 = ( runtimeInputs = (
with pkgs; with pkgs;
[ [
idris2Packages.idris2Lsp
lua-language-server lua-language-server
bash-language-server bash-language-server
hurl hurl
@ -43,8 +54,8 @@ let
in in
pkgs.symlinkJoin { pkgs.symlinkJoin {
name = "helix-wrapped"; name = "helix-wrapped";
paths = [ helix ]; paths = [ helix-wrapped ];
inherit (helix) meta; inherit (helix-wrapped) meta;
buildInputs = [ buildInputs = [
pkgs.makeWrapper pkgs.makeWrapper
]; ];

View file

@ -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;
}

View file

@ -0,0 +1,6 @@
{
name = "idris";
owner = "kayhide";
repo = "tree-sitter-idris";
rev = "c56a25cf57c68ff929356db25505c1cc4c7820f6";
}