Overlays: Difference between revisions

m if the hash type is not included in the hash here, you'll receive the following error: hash does not include a type, nor is the type otherwise known from context
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.
 
(3 intermediate revisions by 2 users 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>final</tt> and <tt>prev</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 their names, too.
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>


Line 402: Line 417:


* [https://nixos.org/nixpkgs/manual/#chap-overlays Overlays  in nixpkgs manual]
* [https://nixos.org/nixpkgs/manual/#chap-overlays Overlays  in nixpkgs manual]
* [https://nixcademy.com/posts/mastering-nixpkgs-overlays-techniques-and-best-practice/ Blog post "Mastering Nixpkgs Overlays: Techniques and Best Practice"]
* [https://blog.flyingcircus.io/2017/11/07/nixos-the-dos-and-donts-of-nixpkgs-overlays/ Blog post "The DOs and DON’Ts of nixpkgs overlays"]
* [https://blog.flyingcircus.io/2017/11/07/nixos-the-dos-and-donts-of-nixpkgs-overlays/ Blog post "The DOs and DON’Ts of nixpkgs overlays"]
* [https://www.youtube.com/watch?v=s2fkgkN55vk&list=PLgknCdxP89ReD6gxl755B6G_CI65z4J2e Nixpkgs Overlays – A place for all excluded packages] - Talk by Nicolas B. Pierron at NixCon 2017
* [https://www.youtube.com/watch?v=s2fkgkN55vk&list=PLgknCdxP89ReD6gxl755B6G_CI65z4J2e Nixpkgs Overlays – A place for all excluded packages] - Talk by Nicolas B. Pierron at NixCon 2017