Home Explore Blog Models CI



nix

7th chunk of `doc/manual/source/language/syntax.md`
e7ce9d5bc540cf72b1d256febc75e2ee2774faa18e06ae1c0000000100000c26
    implication](https://en.wikipedia.org/wiki/Truth_table#Logical_implication)
    Boolean operation.

2.  This is a more subtle condition: if Subversion is built with Apache
    (`httpServer`) support, then the Expat library (an XML library) used
    by Subversion should be same as the one used by Apache. This is
    because in this configuration Subversion code ends up being linked
    with Apache code, and if the Expat libraries do not match, a build-
    or runtime link error or incompatibility might occur.

3.  This assertion says that in order for Subversion to have SSL support
    (so that it can access `https` URLs), an OpenSSL library must be
    passed. Additionally, it says that *if* Apache support is enabled,
    then Apache's OpenSSL should match Subversion's. (Note that if
    Apache support is not enabled, we don't care about Apache's
    OpenSSL.)

4.  The conditional here is not really related to assertions, but is
    worth pointing out: it ensures that if SSL support is disabled, then
    the Subversion derivation is not dependent on OpenSSL, even if a
    non-`null` value was passed. This prevents an unnecessary rebuild of
    Subversion if OpenSSL changes.

## With-expressions

A *with-expression*,

```nix
with e1; e2
```

introduces the set *e1* into the lexical scope of the expression *e2*.
For instance,

```nix
let as = { x = "foo"; y = "bar"; };
in with as; x + y
```

evaluates to `"foobar"` since the `with` adds the `x` and `y` attributes
of `as` to the lexical scope in the expression `x + y`. The most common
use of `with` is in conjunction with the `import` function. E.g.,

```nix
with (import ./definitions.nix); ...
```

makes all attributes defined in the file `definitions.nix` available as
if they were defined locally in a `let`-expression.

The bindings introduced by `with` do not shadow bindings introduced by
other means, e.g.

```nix
let a = 3; in with { a = 1; }; let a = 4; in with { a = 2; }; ...
```

establishes the same scope as

```nix
let a = 1; in let a = 2; in let a = 3; in let a = 4; in ...
```

Variables coming from outer `with` expressions *are* shadowed:

```nix
with { a = "outer"; };
with { a = "inner"; };
a
```

Does evaluate to `"inner"`.

## Comments

- Inline comments start with `#` and run until the end of the line.

  > **Example**
  >
  > ```nix
  > # A number
  > 2 # Equals 1 + 1
  > ```
  >
  > ```console
  > 2
  > ```

- Block comments start with `/*` and run until the next occurrence of `*/`.

  > **Example**
  >
  > ```nix
  > /*
  > Block comments
  > can span multiple lines.
  > */ "hello"
  > ```
  >
  > ```console
  > "hello"
  > ```

  This means that block comments cannot be nested.

  > **Example**
  >
  > ```nix
  > /* /* nope */ */ 1
  > ```
  >
  > ```console
  > error: syntax error, unexpected '*'
  >
  >        at «string»:1:15:
  >
  >             1| /* /* nope */ *
  >              |               ^
  > ```

  Consider escaping nested comments and unescaping them in post-processing.

  > **Example**
  >
  > ```nix
  > /* /* nested *\/ */ 1
  > ```
  >
  > ```console
  > 1
  > ```

Title: Nix Language Features: Conditional Dependencies, `with`-expressions, and Comment Syntax
Summary
This chunk concludes the explanation of Nix's assertion mechanism, detailing how a conditional ensures that a Subversion derivation only depends on OpenSSL if SSL support is explicitly enabled, preventing unnecessary rebuilds. It then introduces `with-expressions` (`with e1; e2`), explaining how they introduce the attributes of `e1` into the lexical scope of `e2`, with a common use case being importing attributes from files. The chunk clarifies the scoping rules for `with`, noting that it doesn't shadow `let` bindings but inner `with` expressions can shadow outer ones. Finally, it covers Nix's comment syntax, describing inline comments (`#`) and block comments (`/* ... */`), explicitly stating that block comments cannot be nested and demonstrating how to escape `*/` for simulated nesting.