From 9f762bf623a17ae4292c3f0f00d9126cb195a0cb Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 11 Jul 2023 14:04:52 +0300 Subject: 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 --- nix/nix-1p/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'nix') diff --git a/nix/nix-1p/README.md b/nix/nix-1p/README.md index 18cbbcd201..48a20e6ba7 100644 --- a/nix/nix-1p/README.md +++ b/nix/nix-1p/README.md @@ -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' ``` +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` / `` Nix files can import each other by using the builtin `import` function and a -- cgit 1.4.1