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

doc: Improve overlays section #255132

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Conversation

infinisil
Copy link
Member

Description of changes

Done in a split off from the docs team meeting, with @henrik-ch tagging along. Not done yet.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@ofborg ofborg bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 14, 2023
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-09-14-documentation-team-meeting-notes-80/33033/1

See the section on `NIX_PATH` in the Nix manual for more details on how to set a value for `<nixpkgs-overlays>.`
If you already have an imported Nixpkgs, you can apply further overlays on top using:
```nix
pkgs.appendOverlays [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be pkgs = pkgs.appendOverlays or does it really stand alone?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be a bit confusing then. I just used pkgs = in the beginning to signal that it's an imported Nixpkgs.

Maybe we could do something like this to make it clearer though:

pkgsModified = pkgs.appendOverlays [ ... ]

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-09-21-documentation-team-meeting-notes-81/33490/1

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-09-28-documentation-team-meeting-notes-83/33599/1

@asymmetric asymmetric added the 6.topic: documentation Meta-discussion about documentation and its workflow label Jan 12, 2024
Copy link
Contributor

@hsjobeki hsjobeki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to call the arguments

final and prev (super is a new term, if you know lib.fix already)

final is also often used in fixed point functions and kind of self explaining if you are familiar with that concept alread.

prev is also kind of self explaining, since the word stems from previous.


The list of overlays can be passed explicitly when importing nixpkgs, for example `import <nixpkgs> { overlays = [ overlay1 overlay2 ]; }`.
The first argument (`self`) corresponds to the final package set. You should use this set for the dependencies of all packages specified in your overlay. For example, all the dependencies of `rr` in the example above come from `self`, as well as the overridden dependencies used in the `boost` override.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The first argument (`self`) corresponds to the final package set. You should use this set for the dependencies of all packages specified in your overlay. For example, all the dependencies of `rr` in the example above come from `self`, as well as the overridden dependencies used in the `boost` override.
The first argument (`final`) corresponds to the final package set after all overlays have been applied. You should use this set for the dependencies of all packages specified in your overlay. For example, all the dependencies of `rr` in the example above come from `final`, as well as the overridden dependencies used in the `boost` override.


NOTE: DO NOT USE THIS in nixpkgs. Further overlays can be added by calling the `pkgs.extend` or `pkgs.appendOverlays`, although it is often preferable to avoid these functions, because they recompute the Nixpkgs fixpoint, which is somewhat expensive to do.
The second argument (`super`) corresponds to the result of the evaluation of the previous stages of Nixpkgs. It does not contain any of the packages added by the current overlay, nor any of the following overlays. This set should be used either to refer to packages you wish to override, or to access functions defined in Nixpkgs. For example, the original recipe of `boost` in the above example, comes from `super`, as well as the `callPackage` function.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The second argument (`super`) corresponds to the result of the evaluation of the previous stages of Nixpkgs. It does not contain any of the packages added by the current overlay, nor any of the following overlays. This set should be used either to refer to packages you wish to override, or to access functions defined in Nixpkgs. For example, the original recipe of `boost` in the above example, comes from `super`, as well as the `callPackage` function.
The second argument (`prev`) corresponds to the result of the evaluation of all previous overlays. It does not contain any of the packages added by the current overlay, nor any of the following overlays. This set should be used either to refer to packages you wish to override, to access functions defined in Nixpkgs, or simply if the addition made needs the original unmodified value. For example, the original recipe of `boost` in the above example, comes from `prev`, as well as the `callPackage` function.

@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 4, 2024
@hsjobeki
Copy link
Contributor

@infinisil also see my approach of the api documentation
#325479

The implementation uses.
final prev

It should be consistent, and the code was refactored long ago to be consistent in that style.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 19, 2024

## Installing overlays {#sec-overlays-install}
## What are overlays {#sec-overlays-definition}
Copy link
Contributor

@hsjobeki hsjobeki Aug 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the important question is "what can i do with overlays". The technical correct definition is not as important in the first sentence.

Suggested change
## What are overlays {#sec-overlays-definition}
## What are overlays {#sec-overlays-definition}
Overlays can be used in general to extend or change existing attribute sets. Common applications are:
- Adding/extending packages to a locally imported version of nixpkgs
- Overriding packages
- Overriding packageSets
- Extending fixedPoint packageSets such as nixpkgs. (We should maybe explain somewhere what those fixed point package sets are.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: documentation Meta-discussion about documentation and its workflow 8.has: documentation
Projects
Status: Postponed
Development

Successfully merging this pull request may close these issues.

6 participants