Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: make sample code valid Nix expressions #354606

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Changes from all 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
24 changes: 18 additions & 6 deletions lib/fixed-points.nix
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,19 @@ rec {
A fixed-point function returning an attribute set has the form

```nix
final: { # attributes }
final: {
# attributes
}
```

where `final` refers to the lazily evaluated attribute set returned by the fixed-point function.

An overlay to such a fixed-point function has the form

```nix
final: prev: { # attributes }
final: prev: {
# attributes
}
```

where `prev` refers to the result of the original function to `final`, and `final` is the result of the composition of the overlay and the original function.
Expand All @@ -177,17 +181,25 @@ rec {

```nix
let
f = final: { # attributes };
overlay = final: prev: { # attributes };
f = final: {
# attributes
};
overlay = final: prev: {
# attributes
};
in extends overlay f;
```

To get the value of `final`, use `lib.fix`:

```nix
let
f = final: { # attributes };
overlay = final: prev: { # attributes };
f = final: {
# attributes
};
overlay = final: prev: {
# attributes
};
g = extends overlay f;
in fix g
```
Expand Down