docs(nix-1p): explain scope of with

This fixes https://github.com/tazjin/nix-1p/issues/13

Due to with's use of a semicolon instead of some kind of bracing
statement, people can get confused about what the scope of a `with`
is.

Hopefully this change should make it more explicit.

Change-Id: Ifaff28e09a2e8b8b244a9c11d44b2780dee284ee
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8951
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
Vincent Ambo 2023-07-11 14:04:52 +03:00 committed by tazjin
parent f9fbc9be85
commit 9f762bf623

View file

@ -326,6 +326,14 @@ let attrs = { a = 15; b = 2; };
in with attrs; a + b # 'a' and 'b' become variables in the scope following 'with' in with attrs; a + b # 'a' and 'b' become variables in the scope following 'with'
``` ```
The scope of a `with`-"block" is the expression immediately following the
semicolon, i.e.:
```nix
let attrs = { /* some attributes */ };
in with attrs; (/* this is the scope of the `with` */)
```
## `import` / `NIX_PATH` / `<entry>` ## `import` / `NIX_PATH` / `<entry>`
Nix files can import each other by using the builtin `import` function and a Nix files can import each other by using the builtin `import` function and a