Help understanding Nixpkgs evaluation


Recently I was trying to expand the capacity of image types that my image viewer (feh) can load, and after a bit of research I have found that the imlib2 library is the one that contains the necessary files.

So knowing this I have been able to achieve my goal by simply overwriting the imlib2 package that uses feh, to imlib2Full. However when I look at the source code of both packages linked by the NixOS search, they both send me to this Nix expression.


About that expression I have a couple of questions:

  1. how is it that this expression is able to set the input arguments to true when called as “imlib2Full”, if the expression does no name parsing, they are false by default, and I don’t see any part of the code that cares about “modifying” the arguments?
    (By the way, I am referring to the variables svgSupport, heifSupport, etc.)

  2. What does this line do?

  inherit (lib) optional optionals; <- THIS LINE

That is, I think I understand what let and inherit do (even the two functions optional and optionals), but why lib is in parentheses, and why optional and optionals are not called as lib.list.optional/s (that’s how it appears in the nixpkgs manual). Anyway, the question is, basically, what does that line do?

Sorry if the question comes across as ‘trivial’ but I really can’t catch the idea. In case I can find the answer somewhere else, I appreciate if you let me know and thanks in advance.

In the pkgs/top-level/all-packages.nix there are probably 2 distinct entries, something like:

foo = callPackage ../misc/foo {};
fooFull = callPackage ../misc/foo { enableBar = true; };

or sometimes you also see this alternative approach:

foo = callPackage ../misc/foo {};
fooFull = foo.override { enableBar = true; };

This is all the “magic”… Explicitely spelling out the differences…


Oh, I didn’t expect that. Thank you very much, I was able to see the call from here as you mentioned.

About the second question, do you have any idea how to interpret the inherit (lib) optional optionals?

Oh, I haven’t realized a second question :smiley: inherit x is just short for x = x and inherit (set) x for x = set.x.


Nice trick. Very grateful for your help.