Skip to content

Commit

Permalink
and inherit section to language basics
Browse files Browse the repository at this point in the history
  • Loading branch information
nrdxp committed Aug 22, 2022
1 parent 3261620 commit 4785d0c
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions src/ch05-01-language-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@

These values are mostly similar to JSON:

| Type | Description | Example
|---|---|---|
| integer | Whole number | 1 |
| float | Floating point number | 1.054 |
| string | UTF-8 string | "hello!" |
| path | File or url | ./default.nix |
| Type | Description | Example
|---------------|-----------------------|------------------|
| integer | Whole number | 1 |
| float | Floating point number | 1.054 |
| string | UTF-8 string | "hello!" |
| path | File or url | ./default.nix |

And these are the collection:
| Type | Description | Example
|---------------|--------------------------|------------------|
| list | Multi-type list | ["hello" 1] |
| attribute set | Key value structure | {key = "value";} |

*NOTE*: Paths are special. They will be resolved relative to the file.
They must start with a "." or "/", similar to how they would be expressed in a shell.
Expand Down Expand Up @@ -112,6 +118,30 @@ let expressions work similarly to how they work in Haskell.
sha256 = "...";
};
```

## Inherit statements

An inherit statement can be used to _pull_ values out of a parent scope
into the current one. Values are whitespace separated and the statement
ends with a `;`.

If an attribute set in parenthesis follows immediately after the `inherit`
keyword, then values can also be pulled directly out of the given set.

In a `let` block, inherit statements can also come before the values they
reference, so long as they are in the same block.

```
let
inherit (set.values) name version;
set.values = {
name = "package";
version = "0.1.0";
};
in
{ inherit name version; }
```

## With expressions

Expand Down

0 comments on commit 4785d0c

Please sign in to comment.