Overlays: Difference between revisions
Tags: Mobile edit Mobile web edit |
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. |
||
| (8 intermediate revisions by 6 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> | 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 182: | Line 182: | ||
# specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= | # specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= | ||
# got: sha256-173gxk0ymiw94glyjzjizp8bv8g72gwkjhacigd1an09jshdrjb4 | # got: sha256-173gxk0ymiw94glyjzjizp8bv8g72gwkjhacigd1an09jshdrjb4 | ||
hash = "173gxk0ymiw94glyjzjizp8bv8g72gwkjhacigd1an09jshdrjb4"; | hash = "sha256-173gxk0ymiw94glyjzjizp8bv8g72gwkjhacigd1an09jshdrjb4"; | ||
}; | }; | ||
}); | }); | ||
| Line 255: | Line 255: | ||
=== Overriding a package inside an extensible attribute set === | === Overriding a package inside an extensible attribute set === | ||
Here is an example of adding plugins to | Here is an example of adding plugins to <code>vimPlugins</code>. | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
final: prev: { | final: prev: { | ||
| 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 295: | Line 310: | ||
final: prev: | final: prev: | ||
# Within the overlay we use a recursive set, though I think we can use `final` as well. | # Within the overlay we use a recursive set, though I think we can use `final` as well. | ||
{ | |||
# nix-shell -p python.pkgs.my_stuff | # nix-shell -p python.pkgs.my_stuff | ||
python = prev.python.override { | python = prev.python.override { | ||
# Careful, we're using a different final and prev here! | # Careful, we're using a different final and prev here! | ||
packageOverrides = | packageOverrides = pyfinal: pyprev: { | ||
my_stuff = | my_stuff = pyprev.buildPythonPackage rec { | ||
pname = "pyaes"; | pname = "pyaes"; | ||
version = "1.6.0"; | version = "1.6.0"; | ||
src = | src = pyprev.fetchPypi { | ||
inherit pname version; | inherit pname version; | ||
hash = "0bp9bjqy1n6ij1zb86wz9lqa1dhla8qr1d7w2kxyn7jbj56sbmcw"; | hash = "0bp9bjqy1n6ij1zb86wz9lqa1dhla8qr1d7w2kxyn7jbj56sbmcw"; | ||
| Line 311: | Line 326: | ||
}; | }; | ||
# nix-shell -p pythonPackages.my_stuff | # nix-shell -p pythonPackages.my_stuff | ||
pythonPackages = python.pkgs; | pythonPackages = final.python.pkgs; | ||
# nix-shell -p my_stuff | # nix-shell -p my_stuff | ||
my_stuff = pythonPackages.buildPythonPackage rec { | my_stuff = final.pythonPackages.buildPythonPackage rec { | ||
pname = "pyaes"; | pname = "pyaes"; | ||
version = "1.6.0"; | version = "1.6.0"; | ||
| 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 | ||
* [[Nixpkgs/Patching Nixpkgs]] | |||
==== References ==== | ==== References ==== | ||