mirror of
https://github.com/ilyakooo0/helix.git
synced 2024-11-24 08:25:17 +03:00
grammars.nix: allow the user to apply overlays (#8749)
You can now apply overlays to the grammar derivations via `grammarOverlays`. Also, the `src` in the derivation is now properly unpacked to the build directory, allowing the user to mutate the source files if they want to.
This commit is contained in:
parent
4229583631
commit
6ab774da0b
45
grammars.nix
45
grammars.nix
@ -5,6 +5,7 @@
|
|||||||
runCommand,
|
runCommand,
|
||||||
yj,
|
yj,
|
||||||
includeGrammarIf ? _: true,
|
includeGrammarIf ? _: true,
|
||||||
|
grammarOverlays ? [],
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
# HACK: nix < 2.6 has a bug in the toml parser, so we convert to JSON
|
# HACK: nix < 2.6 has a bug in the toml parser, so we convert to JSON
|
||||||
@ -48,22 +49,22 @@
|
|||||||
then sourceGitHub
|
then sourceGitHub
|
||||||
else sourceGit;
|
else sourceGit;
|
||||||
in
|
in
|
||||||
stdenv.mkDerivation rec {
|
stdenv.mkDerivation {
|
||||||
# see https://github.com/NixOS/nixpkgs/blob/fbdd1a7c0bc29af5325e0d7dd70e804a972eb465/pkgs/development/tools/parsing/tree-sitter/grammar.nix
|
# see https://github.com/NixOS/nixpkgs/blob/fbdd1a7c0bc29af5325e0d7dd70e804a972eb465/pkgs/development/tools/parsing/tree-sitter/grammar.nix
|
||||||
|
|
||||||
pname = "helix-tree-sitter-${grammar.name}";
|
pname = "helix-tree-sitter-${grammar.name}";
|
||||||
version = grammar.source.rev;
|
version = grammar.source.rev;
|
||||||
|
|
||||||
src =
|
src = source;
|
||||||
if builtins.hasAttr "subpath" grammar.source
|
sourceRoot = if builtins.hasAttr "subpath" grammar.source then
|
||||||
then "${source}/${grammar.source.subpath}"
|
"source/${grammar.source.subpath}"
|
||||||
else source;
|
else
|
||||||
|
"source";
|
||||||
|
|
||||||
dontUnpack = true;
|
|
||||||
dontConfigure = true;
|
dontConfigure = true;
|
||||||
|
|
||||||
FLAGS = [
|
FLAGS = [
|
||||||
"-I${src}/src"
|
"-Isrc"
|
||||||
"-g"
|
"-g"
|
||||||
"-O3"
|
"-O3"
|
||||||
"-fPIC"
|
"-fPIC"
|
||||||
@ -76,13 +77,13 @@
|
|||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
runHook preBuild
|
runHook preBuild
|
||||||
|
|
||||||
if [[ -e "$src/src/scanner.cc" ]]; then
|
if [[ -e src/scanner.cc ]]; then
|
||||||
$CXX -c "$src/src/scanner.cc" -o scanner.o $FLAGS
|
$CXX -c src/scanner.cc -o scanner.o $FLAGS
|
||||||
elif [[ -e "$src/src/scanner.c" ]]; then
|
elif [[ -e src/scanner.c ]]; then
|
||||||
$CC -c "$src/src/scanner.c" -o scanner.o $FLAGS
|
$CC -c src/scanner.c -o scanner.o $FLAGS
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$CC -c "$src/src/parser.c" -o parser.o $FLAGS
|
$CC -c src/parser.c -o parser.o $FLAGS
|
||||||
$CXX -shared -o $NAME.so *.o
|
$CXX -shared -o $NAME.so *.o
|
||||||
|
|
||||||
ls -al
|
ls -al
|
||||||
@ -105,15 +106,17 @@
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
grammarsToBuild = builtins.filter includeGrammarIf gitGrammars;
|
grammarsToBuild = builtins.filter includeGrammarIf gitGrammars;
|
||||||
builtGrammars =
|
builtGrammars = builtins.map (grammar: {
|
||||||
builtins.map (grammar: {
|
inherit (grammar) name;
|
||||||
inherit (grammar) name;
|
value = buildGrammar grammar;
|
||||||
artifact = buildGrammar grammar;
|
}) grammarsToBuild;
|
||||||
})
|
extensibleGrammars =
|
||||||
grammarsToBuild;
|
lib.makeExtensible (self: builtins.listToAttrs builtGrammars);
|
||||||
grammarLinks =
|
overlayedGrammars = lib.pipe extensibleGrammars
|
||||||
builtins.map (grammar: "ln -s ${grammar.artifact}/${grammar.name}.so $out/${grammar.name}.so")
|
(builtins.map (overlay: grammar: grammar.extend overlay) grammarOverlays);
|
||||||
builtGrammars;
|
grammarLinks = lib.mapAttrsToList
|
||||||
|
(name: artifact: "ln -s ${artifact}/${name}.so $out/${name}.so")
|
||||||
|
(lib.filterAttrs (n: v: lib.isDerivation v) overlayedGrammars);
|
||||||
in
|
in
|
||||||
runCommand "consolidated-helix-grammars" {} ''
|
runCommand "consolidated-helix-grammars" {} ''
|
||||||
mkdir -p $out
|
mkdir -p $out
|
||||||
|
Loading…
Reference in New Issue
Block a user