-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Add overlays mechanism to Nixpkgs. #21243
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
Changes from all commits
b28d698
3490df6
4e3c511
0d5a8e4
4eb8d9c
9cedda5
4205b8a
7fda136
5b9131c
120a603
17efce4
8798264
97e75f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| <chapter xmlns="http://docbook.org/ns/docbook" | ||
| xmlns:xlink="http://www.w3.org/1999/xlink" | ||
| xml:id="chap-overlays"> | ||
|
|
||
| <title>Overlays</title> | ||
|
|
||
| <para>This chapter describes how to extend and change Nixpkgs packages using | ||
| overlays. Overlays are used to add layers in the fix-point used by Nixpkgs | ||
| to compose the set of all packages.</para> | ||
|
|
||
| <!--============================================================--> | ||
|
|
||
| <section xml:id="sec-overlays-install"> | ||
| <title>Installing Overlays</title> | ||
|
|
||
| <para>The set of overlays is looked for in the following places. The | ||
| first one present is considered, and all the rest are ignored: | ||
|
|
||
| <orderedlist> | ||
|
|
||
| <listitem> | ||
|
|
||
| <para>As an argument of the imported attribute set. When importing Nixpkgs, | ||
| the <varname>overlays</varname> attribute argument can be set to a list of | ||
| functions, which is described in <xref linkend="sec-overlays-layout"/>.</para> | ||
|
|
||
| </listitem> | ||
|
|
||
| <listitem> | ||
|
|
||
| <para>In the directory pointed by the environment variable | ||
| <varname>NIXPKGS_OVERLAYS</varname>.</para> | ||
| </listitem> | ||
|
|
||
| <listitem> | ||
|
|
||
| <para>In the directory <filename>~/.nixpkgs/overlays/</filename>.</para> | ||
| </listitem> | ||
|
|
||
| </orderedlist> | ||
| </para> | ||
|
|
||
| <para>For the second and third options, the directory should contain Nix expressions defining the | ||
| overlays. Each overlay can be a file, a directory containing a | ||
| <filename>default.nix</filename>, or a symlink to one of those. The expressions should follow | ||
| the syntax described in <xref linkend="sec-overlays-layout"/>.</para> | ||
|
|
||
| <para>The order of the overlay layers can influence the recipe of packages if multiple layers override | ||
| the same recipe. In the case where overlays are loaded from a directory, they are loaded in | ||
| alphabetical order.</para> | ||
|
|
||
| <para>To install an overlay using the last option, you can clone the overlay's repository and add | ||
| a symbolic link to it in <filename>~/.nixpkgs/overlays/</filename> directory.</para> | ||
|
|
||
| </section> | ||
|
|
||
| <!--============================================================--> | ||
|
|
||
| <section xml:id="sec-overlays-layout"> | ||
| <title>Overlays Layout</title> | ||
|
|
||
| <para>Overlays are expressed as Nix functions which accept 2 arguments and return a set of | ||
| packages.</para> | ||
|
|
||
| <programlisting> | ||
| self: super: | ||
|
|
||
| { | ||
| boost = super.boost.override { | ||
| python = self.python3; | ||
| }; | ||
| rr = super.callPackage ./pkgs/rr { | ||
| stdenv = self.stdenv_32bit; | ||
| }; | ||
| } | ||
| </programlisting> | ||
|
|
||
| <para>The first argument, usually named <varname>self</varname>, 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 <varname>rr</varname> in the example above come | ||
| from <varname>self</varname>, as well as the overriden dependencies used in the | ||
| <varname>boost</varname> override.</para> | ||
|
|
||
| <para>The second argument, usually named <varname>super</varname>, | ||
| 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 <varname>boost</varname> | ||
| in the above example, comes from <varname>super</varname>, as well as the | ||
| <varname>callPackage</varname> function.</para> | ||
|
|
||
| <para>The value returned by this function should be a set similar to | ||
| <filename>pkgs/top-level/all-packages.nix</filename>, which contains | ||
| overridden and/or new packages.</para> | ||
|
|
||
| </section> | ||
|
|
||
| </chapter> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,9 @@ has the following highlights: </para> | |
|
|
||
| <itemizedlist> | ||
| <listitem> | ||
| <para></para> | ||
| <para>Nixpkgs is now extensible through overlays. See the <link | ||
| xlink:href="https://nixos.org/nixpkgs/manual/#sec-overlays-install">Nixpkgs | ||
| manual</link> for more information.</para> | ||
| </listitem> | ||
| </itemizedlist> | ||
|
|
||
|
|
@@ -96,6 +98,32 @@ following incompatible changes:</para> | |
| <literal>networking.timeServers</literal>. | ||
| </para> | ||
| </listitem> | ||
|
|
||
| <listitem> | ||
|
|
||
| <para><literal>overridePackages</literal> function no longer exists. | ||
| It is replaced by <link | ||
| xlink:href="https://nixos.org/nixpkgs/manual/#sec-overlays-install"> | ||
| overlays</link>. For example, the following code: | ||
|
|
||
| <programlisting> | ||
| let | ||
| pkgs = import <nixpkgs> {}; | ||
| in | ||
| pkgs.overridePackages (self: super: ...) | ||
| </programlisting> | ||
|
|
||
| should be replaced by: | ||
|
|
||
| <programlisting> | ||
| let | ||
| pkgs = import <nixpkgs> {}; in | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just noticed a double
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fixed as part of commit 0214d94. Thanks! |
||
| in | ||
| import pkgs.path { overlays = [(self: super: ...)] } | ||
| </programlisting> | ||
|
|
||
| </para> | ||
| </listitem> | ||
| </itemizedlist> | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this
super.callPackage? I would thinksuper.callPackagewould use packages fromsuperfor dependencies, where the documentation says to use packages fromself.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E.g. I would think we need to provide a custom
callPackagefor eachselflayer usinglib.callPackagesWith.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically you could use both, but this would get some extra meaning in the futur (security-update branch), because
self.callPackagegoes twice through theselfattribute evaluation. The first one to resolve thecallPackagefunction, and the second time to resolve the dependencies fromselfwhich are captured by thecallPackagefunction.Note that
selfis the same provided to all layers. So usingself.callPackageis for the moment identical tosuper.callPackage, except for this extra hop through the fix-point.I documented it as functions should be taken from
super, because they already captureselfif they have to.Also note that this way, we make it syntactically verifiable, as anything which comes around the dependencies uses
super, and anything which is use to find dependencies usesself.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds reasonable, but can you explain how functions already capture
selfif they need to? E.g. if I have an overlay that adds two new packages:How does the second
super.callPackageget a reference tofooto provide tobar?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I tried it out and looked at the implementation and I now understand why this works, albeit the current behavior is slightly surprising to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any layer defined after could then do: