Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions doc/manual/src/language/advanced-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,40 @@ Derivations can declare some infrequently used optional attributes.
This is useful, for example, when generating self-contained filesystem images with
their own embedded Nix store: hashes found inside such an image refer
to the embedded store and not to the host's Nix store.

- [`__impure`]{#adv-attr-__impure}\
> **Warning**
> This is an experimental feature.
Comment thread
bryanhonof marked this conversation as resolved.
Outdated
>
> To enable it, add the following to [nix.conf](../command-ref/conf-file.md):
>
> ```
> extra-experimental-features = impure-derivations
> ```

If the **experimental** attribute `__impure` is set to `true`, then the
Comment thread
bryanhonof marked this conversation as resolved.
Outdated
derivation won't produce a fixed output. This means that an impure
derivation can have different outputs each time it is built.

Example:

```
derivation {
name = "impure";
builder = /bin/sh;
__impure = true; # mark this derivation as impure
args = [ "-c" "read -n 10 random < /dev/random; echo $random > $out" ];
system = builtins.currentSystem;
}
```

Each time this derivation is built it produces a different output,
since the builder outputs random bytes to $out.

> **Note**
>
Comment thread
bryanhonof marked this conversation as resolved.
Outdated
> Impure derivations have the following traits:
> - They have access to the network
> - Only fixed-output and other impure derivations can depend on
> impure derivations
> - They cannot be [content-addressed](@docroot@/contributing/experimental-features.md#xp-feature-ca-derivations)
Comment thread
bryanhonof marked this conversation as resolved.
Outdated
24 changes: 2 additions & 22 deletions src/libutil/experimental-features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,8 @@ constexpr std::array<ExperimentalFeatureDetails, 11> xpFeatureDetails = {{
.tag = Xp::ImpureDerivations,
.name = "impure-derivations",
.description = R"(
Allow derivations to produce non-fixed outputs by setting the
`__impure` derivation attribute to `true`. An impure derivation can
have differing outputs each time it is built.

Example:

```
derivation {
name = "impure";
builder = /bin/sh;
__impure = true; # mark this derivation as impure
args = [ "-c" "read -n 10 random < /dev/random; echo $random > $out" ];
system = builtins.currentSystem;
}
```

Each time this derivation is built, it can produce a different
output (as the builder outputs random bytes to `$out`). Impure
derivations also have access to the network, and only fixed-output
or other impure derivations can rely on impure derivations. Finally,
an impure derivation cannot also be
[content-addressed](#xp-feature-ca-derivations).
Allow derivations to produce non-fixed outputs. See
[__impure](@docroot@/language/advanced-attributes.md#adv-attr-__impure) for details.
)",
},
{
Expand Down