Skip to content

Commit

Permalink
make example platform-independent and more obvious
Browse files Browse the repository at this point in the history
doing something with the imported expression shows clearly that it has to be
read first
  • Loading branch information
fricklerhandwerk committed Nov 30, 2022
1 parent 8134da1 commit cbed610
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions doc/manual/src/language/import-from-derivation.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,33 @@ Building during evaluation can be disabled by setting [`allow-import-from-deriva

## Example

In the following Nix expression, the derivation `drv` produces a file containing `1` after `sleep`ing for 5 seconds.

Since `1` is a valid Nix expression itself, it can be [`import`](./builtins.md#builtins-import)ed.
That requires reading from the output [store path] of `drv`, which has to be [realise]d before its contents `1` can be evaluated.

[store path]: ../glossary.md#gloss-store-path
In the following Nix expression, the inner derivation `drv` produces a file containing `"hello"`.

```nix
# IFD.nix
let
drv = derivation {
name = "expensive";
name = "hello";
builder = /bin/sh;
args = [ "-c" "${/bin/sleep} 5; echo 1 > $out" ];
args = [ "-c" "echo \"hello\" > $out" ];
system = builtins.currentSystem;
};
in import drv
in "${import drv} world"
```

```shellSession
nix-instantiate IFD.nix --eval --read-write-mode
```

building '/nix/store/6n1mbib4n8l35ncfrbk8g8b3y14c7bi7-expensive.drv'...
1
building '/nix/store/348q1cal6sdgfxs8zqi9v8llrsn4kqkq-hello.drv'...
"hello world"


Since `"hello"` is a valid Nix expression, it can be [`import`](./builtins.md#builtins-import)ed.
That requires reading from the output [store path] of `drv`, which has to be [realise]d before its contents can be read and evaluated.

[store path]: ../glossary.md#gloss-store-path

## Illustration

The following diagram shows how evaluation is interrupted by a build, if the value of a Nix expression specifying a derivation depends on the result of another derivation.
Expand Down

0 comments on commit cbed610

Please sign in to comment.