Skip to content

Commit

Permalink
chore!(nix): add topiary-cli-nix build output
Browse files Browse the repository at this point in the history
This build output uses the grammars from nixpkgs over those provided by
topiary itself.
  • Loading branch information
Erin van der Veen committed Sep 20, 2024
1 parent 71f6619 commit b4f29ce
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 7 deletions.
24 changes: 23 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ let
"Cargo.lock"
"Cargo.toml"
"languages.ncl"
"languages_nix.ncl"
"tests"
"topiary-core"
"topiary-cli"
Expand Down Expand Up @@ -106,12 +107,33 @@ in
cargoExtraArgs = "-p topiary-core";
});

topiary-cli = craneLib.buildPackage (commonArgs
topiary-cli = { nixSupport ? false }: craneLib.buildPackage (commonArgs
// {
inherit cargoArtifacts;
pname = "topiary";
cargoExtraArgs = "-p topiary-cli";
cargoTestExtraArgs = "--no-default-features";


preConfigurePhases = pkgs.lib.optional nixSupport "useNixConfiguration";

# ocamllex is not (yet) packaged in nixpkgs
# ocamllex="${pkgs.tree-sitter-grammars.tree-sitter-ocamllex}/parser" \
useNixConfiguration = ''
bash="${pkgs.tree-sitter-grammars.tree-sitter-bash}/parser" \
css="${pkgs.tree-sitter-grammars.tree-sitter-css}/parser" \
json="${pkgs.tree-sitter-grammars.tree-sitter-json}/parser" \
nickel="${pkgs.tree-sitter-grammars.tree-sitter-nickel}/parser" \
ocaml="${pkgs.tree-sitter-grammars.tree-sitter-ocaml}/parser" \
ocaml_interface="${pkgs.tree-sitter-grammars.tree-sitter-ocaml-interface}/parser" \
rust="${pkgs.tree-sitter-grammars.tree-sitter-rust}/parser" \
toml="${pkgs.tree-sitter-grammars.tree-sitter-toml}/parser" \
tree_sitter_query="${pkgs.tree-sitter-grammars.tree-sitter-query}/parser" \
substituteAllInPlace topiary-config/languages_nix.ncl
mv topiary-config/languages_nix.ncl topiary-config/languages.ncl
'';

postInstall = ''
install -Dm444 topiary-queries/queries/* -t $out/share/queries
'';
Expand Down
16 changes: 10 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@
binPkgs = pkgs.callPackage ./bin/default.nix { };
in
{
packages = {
packages = rec {
inherit (topiaryPkgs)
topiary-cli
topiary-playground
topiary-queries
client-app;

topiary-cli = topiaryPkgs.topiary-cli { };
topiary-cli-nix = topiaryPkgs.topiary-cli { nixSupport = true; };

inherit (binPkgs)
# FIXME: Broken
# generate-coverage
Expand All @@ -74,11 +76,12 @@
update-wasm-grammars
verify-documented-usage;

default = topiaryPkgs.topiary-cli;
default = topiary-cli;
};

checks = {
inherit (topiaryPkgs) clippy clippy-wasm fmt topiary-core topiary-cli topiary-playground audit benchmark;
inherit (topiaryPkgs) clippy clippy-wasm fmt topiary-core topiary-playground audit benchmark;
topiary-cli = topiaryPkgs.topiary-cli { };

## Check that the `lib.pre-commit-hook` output builds/evaluates
## correctly. `deepSeq e1 e2` evaluates `e1` strictly in depth before
Expand All @@ -90,7 +93,8 @@
devShells =
let
checksLight = {
inherit (topiaryPkgs) clippy fmt topiary-core topiary-cli;
inherit (topiaryPkgs) clippy fmt topiary-core;
topiary-cli = topiaryPkgs.topiary-cli { };
};
in
{
Expand All @@ -104,7 +108,7 @@
enable = true;
name = "topiary";
description = "A general code formatter based on tree-sitter.";
entry = "${topiaryPkgs.topiary-cli}/bin/topiary fmt";
entry = "${topiaryPkgs.topiary-cli {}}/bin/topiary fmt";
types = [ "text" ];
};
}
Expand Down
1 change: 1 addition & 0 deletions languages_nix.ncl
72 changes: 72 additions & 0 deletions topiary-config/languages_nix.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
languages = {
bash = {
extensions = ["sh", "bash"],
grammar.source.path = "@bash@",
},

css = {
extensions = ["css"],
grammar.source.path = "@css@",
},

json = {
extensions = [
"json",
"avsc",
"geojson",
"gltf",
"har",
"ice",
"JSON-tmLanguage",
"jsonl",
"mcmeta",
"tfstate",
"tfstate.backup",
"topojson",
"webapp",
"webmanifest"
],
grammar.source.path = "@json@",
},

nickel = {
extensions = ["ncl"],
grammar.source.path = "@nickel@",
},

ocaml = {
extensions = ["ml"],
grammar.source.path = "@ocaml@",
},

ocaml_interface = {
extensions = ["mli"],
grammar.source.path = "@ocaml_interface@",
},

# ocamllex = {
# extensions = ["mll"],
# grammar.source.path = "@ocamllex@",
# },

rust = {
extensions = ["rs"],
indent = " ", # 4 spaces
grammar.source.path = "@rust@",
},

toml = {
extensions = ["toml"],
grammar.source.path = "@toml@",
},

tree_sitter_query = {
extensions = ["scm"],
grammar = {
source.path = "@tree_sitter_query@",
symbol = "tree_sitter_query",
},
},
},
}

0 comments on commit b4f29ce

Please sign in to comment.