Cmp-nixpkgs: two nvim-cmp completion sources for nixpkgs

Mostly a holdout until GitHub - nix-community/rnix-lsp: WIP Language Server for Nix! [maintainer=@aaronjanse] gets autocompletion support for attributes and nixos modules.

This is a simple wrapper around NIX_GET_COMPLETIONS=3 nix eval --read-only self#foo.bar that currently makes some assumptions about how nix/nixos is configured, see the README and source code for more.

It’s split into two sources:

  • nixpkgs, for pkgs, lib, and config.
  • nixos, for nixos modules.

The sources have some support for nested attributes by leveraging tree-sitter to get the surrounding context for the node at cursor, however this can be somewhat fragile.

Link: GitHub - gravndal/cmp-nixpkgs: two nvim-cmp sources for nixpkgs

3 Likes