Overlays: Difference between revisions

imported>SuperSandro2000
m Remove name from pname + version
imported>Gytis-ivaskevicius
Copy-pasta from discourse, at some point someone should clean
Line 24: Line 24:


The 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 why the two arguments got their names, too.
The 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 why the two arguments got their names, too.
== Data flow of overlays (Better explanation???) ==
Source: https://discourse.nixos.org/t/how-to-exclude-packages/13039/4
I recommend final: prev. That's also easier to explain. The first argument is nixpkgs with your overlay applied, and the second argument is nixpkgs without your overlay. So the “final” nixpkgs and the “previous” nixpkgs. This allows you to access things you defined in your overlay along with things from nixpkgs itself.
<syntaxhighlight lang="nix">final: prev: { f = final.firefox; }</syntaxhighlight> would work, but <syntaxhighlight lang="nix">final: prev: { f = prev.firefox; }</syntaxhighlight> would make more sense.
This could be useful:
<syntaxhighlight lang="nix">
final: prev: {
  firefox = prev.firefox.override { ... };
  myBrowser = final.firefox;
}
</syntaxhighlight>
And `final: prev: firefox = final.firefox.override { ... };` would cause infinite recursion.


== Using overlays ==
== Using overlays ==