diff --git a/nixd/docs/dev.md b/nixd/docs/dev.md index 80fba69cc..50dc8fbd7 100644 --- a/nixd/docs/dev.md +++ b/nixd/docs/dev.md @@ -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. + + + +``` + +┌─────────────────┐ +│ 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.