Created
March 2, 2023 02:10
-
-
Save shazow/0ef82e01d0fbf061ad81599e17efe469 to your computer and use it in GitHub Desktop.
Flake for tree-sitter with source grammars available to it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
inputs = { | |
utils.url = "github:numtide/flake-utils"; | |
nixpkgs.url = "/home/shazow/local/src/github.com/NixOS/nixpkgs"; | |
}; | |
outputs = { self, nixpkgs, utils }: | |
utils.lib.eachDefaultSystem (system: | |
let | |
pkgs = import nixpkgs { | |
inherit system; | |
}; | |
grammars = with pkgs.tree-sitter.builtGrammars; [ | |
tree-sitter-solidity | |
]; | |
# Container for the source packages | |
grammars-pkg = pkgs.linkFarm "grammars" (map (g: { name = g.pname; path = g.src.outPath; }) grammars); | |
# Config for tree-sitter to find the source packages | |
tree-sitter-config = pkgs.writeTextFile { | |
name = "tree-sitter-config"; | |
destination = "/config.json"; | |
text = builtins.toJSON { "parser-directories" = [grammars-pkg.outPath ]; }; | |
}; | |
in { | |
devShell = pkgs.mkShell { | |
buildInputs = [ | |
pkgs.tree-sitter # We don't use withPlugins because we want the source packages, rather than built | |
grammars-pkg | |
]; | |
# Decorative prompt override so we know when we're in a dev shell | |
shellHook = '' | |
export PS1="[dev] $PS1" | |
export TREE_SITTER_DIR=${tree-sitter-config} | |
''; | |
}; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment