In nix, overlay is a function with 2 arguments: self
and super
. Based on the manual, self
corresponds to the final package set (or some others call it result of the fix point calculation) and only to be used when dealing with dependencies. While super
is the result of the evaluation of the previous stages of nixpkgs
and only to be used when you refer to packages you want to override or to access certain function.
Sadly I don't really understand this. In what way that the nixpkgs
gets updated by the overlays such that there's 2 restriction mentioned above?
Overlays are Nix functions which accept two arguments, conventionally called self and super , and return a set of packages. For example, the following is a valid overlay. self: super: { boost = super.boost.override { python = self.python3; }; rr = super.callPackage ./pkgs/rr { stdenv = self.stdenv_32bit; }; }
The Nix Packages collection (Nixpkgs) is a set of thousands of packages for the Nix package manager, released under a permissive MIT/X11 license. Packages are available for several platforms, and can be used with the Nix package manager on most GNU/Linux distributions as well as NixOS.
Description. The command nix-shell will build the dependencies of the specified derivation, but not the derivation itself. It will then start an interactive shell in which all environment variables defined by the derivation path have been set to their corresponding values, and the script $stdenv/setup has been sourced.
These restrictions follow from the requirement that evaluation of an attribute should terminate.
Suppose you want to override the hello
package. To reference the old definition of the package, you need to use super.hello
, because that attribute can be evaluated without evaluating the hello
definition in your overlay. If you would instead reference self.hello
, that means that for evaluating the final hello
attribute, Nix will have to evaluate self.hello
, which references the final hello
attribute, which references self.hello
, and so on, creating an infinite recursion.
self
can actually be used to reference functions, but the convention seems to be to use super
instead. The idea that the next overlay may monkey-patch the lib.head
function is not very enticing, although using super
the same can still be done in a previous overlay.
You may also want to check out this excellent NixCon 2017 presentation by Nicolas. He both introduces the concept and explains how you can use it in the best way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With