7

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?

1
  • @DavidGrayson Sorry if I'm not clear enough. The 2 restrictions I mentioned above are: self is only to be used when dealing with dependencies, super is only to be used when we need to refer to packages or to use certain function.
    – autumn322
    Sep 19, 2018 at 23:55

1 Answer 1

8

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.

1
  • edit queue is full ... nevermind ... will delete comment later
    – milahu
    Oct 9, 2021 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.