From f49d541a622122cc907ee76c0ca99dcfa51cef66 Mon Sep 17 00:00:00 2001 From: Vladimir Kidiaev Date: Mon, 14 Sep 2026 00:33:30 +0400 Subject: [PATCH 1/6] Add Nix tree-sitter grammar --- Cargo.lock | 11 +++++++++++ Cargo.toml | 1 + crates/codebook/Cargo.toml | 1 + 3 files changed, 13 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 198aea2..ff6ec4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -391,6 +391,7 @@ dependencies = [ "tree-sitter-javascript", "tree-sitter-lua", "tree-sitter-md", + "tree-sitter-nix", "tree-sitter-ocaml", "tree-sitter-odin-codebook", "tree-sitter-php", @@ -2743,6 +2744,16 @@ dependencies = [ "tree-sitter-language", ] +[[package]] +name = "tree-sitter-nix" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4952a9733f3a98f6683a0ccd1035d84ab7a52f7e84eeed58548d86765ad92de3" +dependencies = [ + "cc", + "tree-sitter-language", +] + [[package]] name = "tree-sitter-ocaml" version = "0.25.0" diff --git a/Cargo.toml b/Cargo.toml index 758a877..ec6ed40 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,6 +67,7 @@ tree-sitter-java = "<0.25.0" tree-sitter-javascript = "<0.26.0" tree-sitter-lua = "<0.25.0" tree-sitter-md = "<0.6.0" +tree-sitter-nix = "0.3.0" tree-sitter-ocaml = "<0.26" tree-sitter-odin-codebook = "1.4.0" tree-sitter-php = "<0.25.0" diff --git a/crates/codebook/Cargo.toml b/crates/codebook/Cargo.toml index 0d70d04..2f46112 100644 --- a/crates/codebook/Cargo.toml +++ b/crates/codebook/Cargo.toml @@ -43,6 +43,7 @@ codebook-tree-sitter-just.workspace = true codebook-tree-sitter-latex.workspace = true tree-sitter-lua.workspace = true tree-sitter-md.workspace = true +tree-sitter-nix.workspace = true tree-sitter-ocaml.workspace = true tree-sitter-odin-codebook.workspace = true tree-sitter-php.workspace = true From e72c2da20a0aa51eb5277b36a0a002b7be33057b Mon Sep 17 00:00:00 2001 From: Vladimir Kidiaev Date: Mon, 14 Sep 2026 00:59:01 +0400 Subject: [PATCH 2/6] Add Nix tree-sitter queries --- crates/codebook/src/queries/nix.scm | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 crates/codebook/src/queries/nix.scm diff --git a/crates/codebook/src/queries/nix.scm b/crates/codebook/src/queries/nix.scm new file mode 100644 index 0000000..45edd67 --- /dev/null +++ b/crates/codebook/src/queries/nix.scm @@ -0,0 +1,30 @@ +(comment) @comment + +; Strings +(string_expression) @string +(indented_string_expression (string_fragment) @string.heredoc) +[(path_expression) (hpath_expression) (spath_expression)] @string.special +(uri_expression) @string.special + +; Parameters +(function_expression + universal: (identifier) @identifier.parameter) +(formal + name: (identifier) @identifier.parameter) + +; Fields +(inherit + attrs: (inherited_attrs attr: (identifier) @identifier.field)) +(inherit_from + attrs: (inherited_attrs attr: (identifier) @identifier.field)) + +; Constants, let binds are immutable, don't fall into variables category +(binding + attrpath: (attrpath (identifier)) @identifier.constant) + +; Function +(apply_expression + function: [ + (variable_expression (identifier)) @identifier.function + (select_expression + attrpath: (attrpath attr: (identifier) @identifier.function .))]) From 6bd5c4aa017546584c305f6781f7cd1c282293c9 Mon Sep 17 00:00:00 2001 From: Vladimir Kidiaev Date: Mon, 14 Sep 2026 01:04:54 +0400 Subject: [PATCH 3/6] Add Nix to queries.rs --- crates/codebook/src/queries.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/codebook/src/queries.rs b/crates/codebook/src/queries.rs index 12e9e32..6f72f47 100644 --- a/crates/codebook/src/queries.rs +++ b/crates/codebook/src/queries.rs @@ -21,6 +21,7 @@ pub enum LanguageType { Latex, Lua, Markdown, + Nix, OCaml, Odin, Php, @@ -234,6 +235,13 @@ pub static LANGUAGE_SETTINGS: &[LanguageSetting] = &[ query: include_str!("queries/markdown.scm"), extensions: &["md", "markdown"], }, + LanguageSetting { + type_: LanguageType::Nix, + ids: &["nix"], + dictionary_ids: &[], + query: include_str!("queries/nix.scm"), + extensions: &["nix"], + }, LanguageSetting { type_: LanguageType::Bash, ids: &[ @@ -344,6 +352,7 @@ impl LanguageSetting { LanguageType::Latex => Some(codebook_tree_sitter_latex::LANGUAGE.into()), LanguageType::Lua => Some(tree_sitter_lua::LANGUAGE.into()), LanguageType::Markdown => Some(tree_sitter_md::LANGUAGE.into()), + LanguageType::Nix => Some(tree_sitter_nix::LANGUAGE.into()), LanguageType::OCaml => Some(tree_sitter_ocaml::LANGUAGE_OCAML.into()), LanguageType::Odin => Some(tree_sitter_odin_codebook::LANGUAGE.into()), LanguageType::Php => Some(tree_sitter_php::LANGUAGE_PHP.into()), From c44737404661722a6b7394da67dbc4cc0c182414 Mon Sep 17 00:00:00 2001 From: Vladimir Kidiaev Date: Mon, 14 Sep 2026 02:57:26 +0400 Subject: [PATCH 4/6] Add example.nix --- crates/codebook/tests/examples/example.nix | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 crates/codebook/tests/examples/example.nix diff --git a/crates/codebook/tests/examples/example.nix b/crates/codebook/tests/examples/example.nix new file mode 100644 index 0000000..9412aa0 --- /dev/null +++ b/crates/codebook/tests/examples/example.nix @@ -0,0 +1,29 @@ +# Commment with a typo +{ + description = "A useful dev shell for the packge"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flakeUtils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flakeUtils }: + flakeUtils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + verion = "0.1.0"; + in + { + devShells.defualt = pkgs.mkShell { + buildInputs = [ pkgs.cargo pkgs.rustc ]; + shellHook = '' + echo "Entring dev shell version ${verion}" + ''; + }; + packages.default = pkgs.stdenv.mkDerivation { + pname = "my-projet"; + version = verion; + src = ./.; + }; + }); +} From 6c56868e356bd54c19a5ae6d6ec09da26ad11069 Mon Sep 17 00:00:00 2001 From: Vladimir Kidiaev Date: Mon, 14 Sep 2026 02:58:09 +0400 Subject: [PATCH 5/6] Add tests for Nix --- crates/codebook/tests/languages/main.rs | 1 + crates/codebook/tests/languages/test_nix.rs | 28 +++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 crates/codebook/tests/languages/test_nix.rs diff --git a/crates/codebook/tests/languages/main.rs b/crates/codebook/tests/languages/main.rs index 5900037..0bb4ecf 100644 --- a/crates/codebook/tests/languages/main.rs +++ b/crates/codebook/tests/languages/main.rs @@ -17,6 +17,7 @@ mod test_just; mod test_latex; mod test_lua; mod test_markdown; +mod test_nix; mod test_ocaml; mod test_odin; mod test_php; diff --git a/crates/codebook/tests/languages/test_nix.rs b/crates/codebook/tests/languages/test_nix.rs new file mode 100644 index 0000000..5431abd --- /dev/null +++ b/crates/codebook/tests/languages/test_nix.rs @@ -0,0 +1,28 @@ +use codebook::queries::LanguageType; + +use super::utils::assert_spelling_at; + +#[test] +fn test_nix_location() { + let sample_text = include_str!("../examples/example.nix"); + + assert_spelling_at( + LanguageType::Nix, + sample_text, + &[ + ("Commment", &[0]), + ("packge", &[0]), + // Flagged at the let binding declaration only; + // the `${verion}` interpolation and `version = verion;` usages are not flagged + ("verion", &[0]), + ("defualt", &[0]), + ("Entring", &[0]), + ("projet", &[0]), + ("pname", &[0]), + // Below strings are conventional / very common abbreviations in Nix, but they are not keywords, + // so they must be flagged as misspelled + ("nixpkgs", &[0, 2]), + ("pkgs", &[3]), + ], + ); +} From aa03da6b9494a42b4ed437e359d729bb9b2d0204 Mon Sep 17 00:00:00 2001 From: Vladimir Kidiaev Date: Mon, 14 Sep 2026 03:04:34 +0400 Subject: [PATCH 6/6] Update README Add Nix to supported langauges --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c1b598a..7344f6a 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ Codebook uses a hierarchical configuration system with global (user-level) and p ✅ **Good to go:** C, Go, Java, JavaScript, Lua, Markdown, Odin, Plain Text, Python, Ruby, Rust, TOML, TypeScript, Zig -⚠️ **Supported, needs more testing** (help us improve!): Astro, Bash, C#, C++, CSS, Dart, Elixir, Erlang, Haskell, HTML, Just, LaTeX, OCaml, PHP, Svelte, Swift, Typst, VHDL, Vue, YAML +⚠️ **Supported, needs more testing** (help us improve!): Astro, Bash, C#, C++, CSS, Dart, Elixir, Erlang, Haskell, HTML, Just, LaTeX, Nix, OCaml, PHP, Svelte, Swift, Typst, VHDL, Vue, YAML If Codebook is not marking issues you think it should, please file a GitHub issue!