Yeah, that is mostly an implementation detail and I will send you to the module system source code if you want to learn more. I can only describe what it seems to do on the outside as I have not actually needed to dig any deeper than the stuff I linked.
The module system, roughly, collects all modules, starting with the module inside the <nixos-config>
file (usually configuration.nix
) and the default modules from module-list.nix
, and then adding stuff listed in their imports
, recursively. Then paths in imports
are import
ed. Next, if a collected module is a function expression, it gets passed lib
, config
, options
and pkgs
as arguments (the latter through internal _module.args.pkgs
option), plus whatever is passed to specialArgs
or extraArgs
(when calling eval-config
manually, e.g. using lib.nixosSystem
in a flake, but that is discouraged). Then all the resulting attribute sets (mainly containing options
, config
attributes) are merged resulting in a single big attribute set.
(By the steps described, I do not mean neatly delineated phases but rather climbing up the function call stack.)