Skip to content

feat: add flake-aware Nix language support#412

Open
BrockLeeBytes wants to merge 6 commits intotirth8205:mainfrom
BrockLeeBytes:nix-extension
Open

feat: add flake-aware Nix language support#412
BrockLeeBytes wants to merge 6 commits intotirth8205:mainfrom
BrockLeeBytes:nix-extension

Conversation

@BrockLeeBytes
Copy link
Copy Markdown

@BrockLeeBytes BrockLeeBytes commented Apr 30, 2026

Summary

Adds .nix as a supported language in the Tree-sitter parser with flake-aware semantics. No new runtime dependency — tree-sitter-language-pack already ships the Nix grammar.

What gets extracted:

  • Top-level and nested attrset bindings (attrpath = expr;) become Function nodes with flattened dotted names (e.g. packages.default, devShells.default). CONTAINS edges wire the file to each top-level binding.
  • In flake.nix, inputs.<name>.url = "..." strings (both the flat and the nested inputs = { nixpkgs.url = "..."; ... }; forms) emit IMPORTS_FROM edges targeting the URL.
  • import <path> and callPackage <path> <args> applications in any .nix file emit IMPORTS_FROM edges. Relative paths are resolved against the caller's directory (mirrors the Bash source handling); URLs and bare identifiers are preserved as-is.

Changes

  • code_review_graph/parser.py:
    • EXTENSION_TO_LANGUAGE: .nixnix
    • Empty entries in _CLASS_TYPES / _FUNCTION_TYPES / _IMPORT_TYPES / _CALL_TYPES (pattern matches Elixir/Bash)
    • New dispatch in the main walker for binding nodes
    • New _extract_nix_constructs method + three helpers (_is_nix_flake_file, _nix_attrpath_parts, _extract_nix_flake_input_urls, _extract_nix_import_targets)
    • _do_resolve_module: new nix branch for relative .nix path resolution
  • tests/fixtures/sample.nix, tests/fixtures/sample_module.nix: flake and non-flake fixtures
  • tests/test_multilang.py: new TestNixParsing class (7 tests covering language detection, node language tags, top-level binding flattening, flake inputs.*.url edges, import/callPackage edges, non-flake negative case, and CONTAINS wiring)
  • CLAUDE.md, README.md, CHANGELOG.md, diagrams/generate_diagrams.py: docs and language-coverage diagram updated

Verification

Automated:

uv run pytest tests/test_multilang.py::TestNixParsing -v    # 7 passed
uv run ruff check code_review_graph/parser.py               # clean
uv run mypy code_review_graph/parser.py --ignore-missing-imports --no-strict-optional  # clean

Full suite: +7 new passes, 0 regressions (the 60 pre-existing failures in TestJuliaParsing / TestGDScriptParsing / test_main's TestApplyToolFilter are all unrelated to this change — confirmed by running the full suite on HEAD vs. HEAD~3).

Test plan

  • uv run pytest tests/test_multilang.py::TestNixParsing -v — all 7 pass
  • uv run pytest tests/ --tb=short -q — no new regressions
  • uv run ruff check code_review_graph/parser.py — clean
  • uv run mypy code_review_graph/parser.py --ignore-missing-imports --no-strict-optional — clean
  • E2E build on a real multi-file flake — parses, produces expected nodes/edges via MCP tools

Notes

  • The non-flake test (test_non_flake_file_has_no_input_edges) verifies that the inputs.*.url branch only fires when the file basename is flake.nix, so random .url bindings in NixOS modules don't get misinterpreted as flake inputs.
  • The flake-input branch on the nested form (inputs = { nixpkgs.url = "..."; ... };) is necessary — the flat form (inputs.nixpkgs.url = "...";) only covers part of real-world flake usage.

@BrockLeeBytes BrockLeeBytes changed the title Add flake-aware Nix language support feat: add flake-aware Nix language support Apr 30, 2026
dpesch added a commit to 11com7/code-review-graph that referenced this pull request May 3, 2026
Adds Nix (.nix) parsing via tree-sitter-nix. Indexes attribute set
bindings as Function nodes, emits IMPORTS_FROM edges for flake
inputs.*.url strings and import/callPackage applications.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant