Overlays: Difference between revisions
→See also: Added link to Nixpkgs Overlays talk |
Mdaniels5757 (talk | contribs) m clarify |
||
| (10 intermediate revisions by 9 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 43: | Line 43: | ||
And <syntaxhighlight lang="nix">final: prev: firefox = final.firefox.override { ... };</syntaxhighlight> would cause infinite recursion. | And <syntaxhighlight lang="nix">final: prev: { firefox = final.firefox.override { ... }; }</syntaxhighlight> would cause infinite recursion. | ||
== Using overlays == | == Using overlays == | ||
| Line 182: | Line 182: | ||
# specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= | # specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= | ||
# got: sha256-173gxk0ymiw94glyjzjizp8bv8g72gwkjhacigd1an09jshdrjb4 | # got: sha256-173gxk0ymiw94glyjzjizp8bv8g72gwkjhacigd1an09jshdrjb4 | ||
hash = "173gxk0ymiw94glyjzjizp8bv8g72gwkjhacigd1an09jshdrjb4"; | hash = "sha256-173gxk0ymiw94glyjzjizp8bv8g72gwkjhacigd1an09jshdrjb4"; | ||
}; | }; | ||
}); | }); | ||
| Line 225: | Line 225: | ||
final: prev: { | final: prev: { | ||
# elements of pkgs.gnome must be taken from gfinal and gprev | # elements of pkgs.gnome must be taken from gfinal and gprev | ||
gnome = prev.gnome.overrideScope | gnome = prev.gnome.overrideScope (gfinal: gprev: { | ||
mutter = gprev.mutter.overrideAttrs (oldAttrs: { | mutter = gprev.mutter.overrideAttrs (oldAttrs: { | ||
patches = oldAttrs.patches ++ [ | patches = oldAttrs.patches ++ [ | ||
| 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 295: | Line 295: | ||
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 311: | ||
}; | }; | ||
# 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 397: | Line 397: | ||
* [https://nixos.org/manual/nixpkgs/unstable/#using-community-maintained-rust-toolchains Details in the Nixpkgs manual for using Rust overlays] | * [https://nixos.org/manual/nixpkgs/unstable/#using-community-maintained-rust-toolchains Details in the Nixpkgs manual for using Rust overlays] | ||
* [https://github.com/peter-sa/nixos-rocm Overlay for Radeon Open-Compute packages] | * [https://github.com/peter-sa/nixos-rocm Overlay for Radeon Open-Compute packages] | ||
* [https://github.com/garbas/nixpkgs-python Overlay by Rok Garbas for a set of python packages built by pypi2nix] | * [https://github.com/garbas/nixpkgs-python Overlay by Rok Garbas for a set of python packages built by pypi2nix (archived)] | ||
== See also == | == See also == | ||
* [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 ==== | ||