Skip to content

Commit

Permalink
docs: add nixd worker model
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Dec 24, 2023
1 parent 9650260 commit 7cb8ab8
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions nixd/docs/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,47 @@

### Design

#### Memory model about nix language & nixd workers

**TLDR: Evaluation is not memory-safe and must be performed in a separeted address space.**

In the context of the Nix language, laziness refers to the evaluation strategy where expressions are not immediately evaluated when they are encountered, but rather when their values are actually needed.
This means that the evaluation of an expression is deferred until it is required to produce a result.

One consequence of lazy evaluation is the potential for circular references or circular dependencies.


Our upstream [C++ nix](https://github.com/NixOS/nix) uses a garbage collector and never actively free used memories.
Thus all evaluators should be used in "worker" processes.

<!--
digraph {
Controller -> Worker [ label = "JSON RPC" dir = "both" ]
Worker -> "Workspace Files"
Controller -> "Workspace Files"
}
-->

```
┌─────────────────┐
│ Controller │ ─┐
└─────────────────┘ │
▲ │
│ │
│ JSON RPC │
▼ │
┌─────────────────┐ │
│ Worker │ │
└─────────────────┘ │
│ │
│ │
▼ │
┌─────────────────┐ │
│ Workspace Files │ ◀┘
└─────────────────┘
```

#### 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.
Expand Down

0 comments on commit 7cb8ab8

Please sign in to comment.