Overlays: Difference between revisions
Add another link to a comprehensive nixpkgs overlays article |
Add an example for overriding Perl packages, since the other languages have examples of special cases. This also helps make a definitive version that can be updated (going forward) for people coming from search engines too, rather than forum posts...etc. from years ago. |
||
| (2 intermediate revisions by one other user not shown) | |||
| Line 26: | Line 26: | ||
As you can see, <tt>final</tt> is the same for every stage, but <tt>prev</tt> comes from only the stage before. So when you define an attribute <tt>foo</tt> in the set to override it, within that overlay <tt>final.foo</tt> will be its version, and <tt>prev.foo</tt> will be the non-overriden version. This is why you see patterns like <tt>foo = prev.foo.override { ... }</tt>. | As you can see, <tt>final</tt> is the same for every stage, but <tt>prev</tt> comes from only the stage before. So when you define an attribute <tt>foo</tt> in the set to override it, within that overlay <tt>final.foo</tt> will be its version, and <tt>prev.foo</tt> will be the non-overriden version. This is why you see patterns like <tt>foo = prev.foo.override { ... }</tt>. | ||
The names <tt> | The alternate names <tt>self</tt> and <tt>super</tt> might remind you of inheritance in object-oriented languages. In fact, overlays are exactly the same thing as subclasses, with regards to overriding and calling methods. This data flow is also how objects know which method to call. This is probably how the two arguments got those names, too. | ||
== Data flow of overlays (alternative explanation) == | == Data flow of overlays (alternative explanation) == | ||
| Line 283: | Line 283: | ||
}; | }; | ||
}; | }; | ||
</syntaxhighlight> | |||
=== Perl Package overlays === | |||
Perl packages require some extra care prevent the error <code>undefined variable 'perl'</code>. This example turns off tests for the <code>example</code> package: | |||
<syntaxhighlight lang="nix"> | |||
final: prev: { | |||
perlPackages = prev.perlPackages // { | |||
example = prev.perlPackages.example.overrideAttrs (attrs: | |||
{ doChecks = false; } | |||
) | |||
}; | |||
}; | |||
</syntaxhighlight> | </syntaxhighlight> | ||