Skip to content

Commit

Permalink
docs: update for nixd-next (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc authored Apr 19, 2024
1 parent 52a0057 commit 7b339bc
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 558 deletions.
69 changes: 4 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,87 +6,26 @@
</p>
</div>

# WIP Note 🚧

`nixd-next` is still WIP! Please see https://github.com/nix-community/nixd/issues/283 for the migration plan.

[Released versions](https://github.com/nix-community/nixd/releases/) contain stable nixd code. If you encountered any problem with this nightly version, please use to our released version in nixpkgs.

The following description is suitable for stable releases, but outdated for `nixd-next` (i.e. this version).

## About

This is a Nix language server that directly uses (i.e., is linked with) the official Nix library (https://github.com/NixOS/nix).
This is a feature-rich nix language server interoperating with C++ nix.

Some notable features provided by linking with the Nix library include:

- Nixpkgs option support, for all option system (NixOS/home-manager/flake-parts).
- Diagnostics and evaluation that produce identical results as the real Nix command.
- Nixpkgs package complete, lazily evaluated.
- Shared eval caches (flake, file) with your system's Nix.
- Native support for cross-file analysis (goto definition to locations in nixpkgs).
- Precise Nix language support. We do not maintain "yet another parser & evaluator".
- Support for built-ins, including Nix plugins.


## Features Preview


<details><summary>Home-manager options auto-completion & goto declaration</summary>

![options-example](https://github.com/nix-community/nixd/assets/36667224/43e00a8e-c2e6-4598-b188-f5e95d708256)

See how to configure option system: https://github.com/nix-community/nixd/blob/main/nixd/docs/user-guide.md#options

</details>

<details><summary>Write a package using nixd</summary>

![write-package](https://github.com/nix-community/nixd/assets/36667224/a974c60e-096e-4964-a5d4-fc926963d577)

</details>

<details><summary>Native cross-file analysis</summary>

![package](nixd/docs/images/3e4fc99c-7a20-42be-a337-d1746239c731.png)

We support goto-definition on nix derivations!
Just `Ctrl + click` to see where is a package defined.

![goto-def-pkg-2](https://github.com/nix-community/nixd/assets/36667224/726c711f-cf75-48f4-9f3b-40dd1b9f53be)

And also for nix lambda:

![lambda-location](https://github.com/nix-community/nixd/assets/36667224/5792da0b-8152-4e51-9b0e-0387b045eeb5)

See how to configure the evaluator for cross-file analysis: https://github.com/nix-community/nixd/blob/main/nixd/docs/user-guide.md#evaluation

</details>

<details><summary>Handle evaluations exactly same as nix evaluator</summary>

![infinte-recursion](nixd/docs/images/9ed5e08a-e439-4b09-ba78-d83dc0a8a03f.png)

</details>

<details><summary>Support *all* builtins</summary>

![eval-builtin-json](nixd/docs/images/59655838-36a8-4145-9717-f2009e0efef9.png)

And diagnostic:

![eval-builtin-diagnostic](nixd/docs/images/f6e10994-41e4-4a03-84a2-ef275fb402fd.png)
- Support for cross-file analysis (goto definition to locations in nixpkgs).

</details>

## Get Started

You can *try nixd without installation*.
We have tested some working & reproducible [editor environments](/nixd/docs/editors/editors.md) and example [configurations & workspaces](/nixd/docs/examples).
We have tested some working & reproducible [editor environments](/nixd/docs/editors/editors.md).

## Resources

- [Editor Setup](nixd/docs/editor-setup.md)
- [User Guide](nixd/docs/user-guide.md)
- [Configuration Examples](nixd/docs/examples)
- [Developers' Manual](nixd/docs/dev.md) (internal design, contributing):
- Project matrix room: https://matrix.to/#/#nixd:matrix.org
37 changes: 0 additions & 37 deletions nixd/docs/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,43 +44,6 @@ digraph {
└─────────────────┘
```

#### How does language information being collected?

Nix expressions are evaluated using the `nix::Expr::eval` virtual method, with dynamic name bindings and lookups performed in `Env`s.
The resulting evaluation is stored in `Value`s.

Link: https://github.com/NixOS/nix/blob/61ddfa154bcfa522819781d23e40e984f38dfdeb/src/libexpr/nixexpr.hh#L161

It is mandatory to preserve the information for language services, rather than discarding it away (what nix itself do).
The codebase achieves this by inheriting all Nix AST node classes and overriding the virtual `eval` method to call the super-class `eval` and then invoke a custom callback.

##### Why does nix evaluator see your data structure, instead of parsing file by itself?

Nix parsing and evaluation are cached, and the caching interface is public.
When you open a file in your workspace, we first parse it to obtain normal Nix abstract syntax trees (ASTs).
We then recursively rewrite all AST nodes with our own data structure, creating a new tree.
Finally, we call `cacheFile` in Nix to inject our own data structure into the evaluator.


#### How does cross-file analysis work?

For example, you write a NixOS module:

```nix
{ config, lib, pkgs, ... }:
{
# Some stuff
}
```

The file itself is a valid Nix expression, specifically an `ExprLambda`. However, it is important to know the arguments that are passed when invoking lambdas. This is necessary when writing NixOS configurations, as it helps to determine what can be used in `pkgs` and the library functions in `lib`.

Here's how it works:

When you open the file, `nixd` will parse it for you, and rewrite and inject it into the Nix evaluator (as mentioned earlier). Then, the top-level evaluation process begins, and the lambdas are evaluated. Our callback function is invoked, and the necessary information is collected in the callbacks.


### Testing

This project is tested by "unit tests" and "regression tests".
Expand Down
24 changes: 0 additions & 24 deletions nixd/docs/examples/README.md

This file was deleted.

11 changes: 0 additions & 11 deletions nixd/docs/examples/flake/.nixd.json

This file was deleted.

10 changes: 0 additions & 10 deletions nixd/docs/examples/flake/default.nix

This file was deleted.

44 changes: 0 additions & 44 deletions nixd/docs/examples/flake/flake.lock

This file was deleted.

15 changes: 0 additions & 15 deletions nixd/docs/examples/flake/flake.nix

This file was deleted.

9 changes: 0 additions & 9 deletions nixd/docs/examples/options/home-manager/.nixd.json

This file was deleted.

48 changes: 0 additions & 48 deletions nixd/docs/examples/options/home-manager/flake.lock

This file was deleted.

34 changes: 0 additions & 34 deletions nixd/docs/examples/options/home-manager/flake.nix

This file was deleted.

12 changes: 0 additions & 12 deletions nixd/docs/examples/options/nixos/.nixd.json

This file was deleted.

20 changes: 0 additions & 20 deletions nixd/docs/examples/options/nixos/module.nix

This file was deleted.

10 changes: 0 additions & 10 deletions nixd/docs/examples/package/.nixd.json

This file was deleted.

10 changes: 0 additions & 10 deletions nixd/docs/examples/package/package.nix

This file was deleted.

Loading

0 comments on commit 7b339bc

Please sign in to comment.