Skip to content

Instantly share code, notes, and snippets.

@shazow
Created March 2, 2023 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shazow/0ef82e01d0fbf061ad81599e17efe469 to your computer and use it in GitHub Desktop.
Save shazow/0ef82e01d0fbf061ad81599e17efe469 to your computer and use it in GitHub Desktop.
Flake for tree-sitter with source grammars available to it.
{
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