Modules vs imports
pcasaretto opened this issue · comments
Hi there!
On this section (https://nixos-and-flakes.thiscute.world/nixos-with-flakes/modularize-the-configuration), there is a mention to imports
, but the linked documentation points to modules
.
Looking at the example it seems modules
is the right parameter name. However, I have seen imports
in several other places
Can you ask you to enlighten me and explain these parameters?
- modules is a parameter of the function nixpkgs.lib.nixosSystem
- imports is used in submodules to import other submodules.
Where should the docs point to then?
If modules
is this https://github.com/NixOS/nixpkgs/blob/23.11/flake.nix#L24
It shouldn't point to https://nixos.org/manual/nixpkgs/unstable/#module-system-lib-evalModules, right?
Sorry if I'm being obtuse, I'm trying to wrap my head around this. Thanks again for the book. I've already learned a lot!
Will modules = args.modules ++ [{
eventually find it's way into a lib.evalModules
?
Will
modules = args.modules ++ [{
eventually find it's way into alib.evalModules
?
Yep, it's just part of the attrset passed into import ./nixos/lib/eval-config.nix
:
https://github.com/NixOS/nixpkgs/blob/057f9aecfb71c4437d2b27d3323df7f93c010b7e/flake.nix#L22-L35
nixosSystem = args:
import ./nixos/lib/eval-config.nix (
args // {
modules = args.modules ++ [{
system.nixos.versionSuffix =
".${final.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}.${self.shortRev or "dirty"}";
system.nixos.revision = final.mkIf (self ? rev) self.rev;
}];
} // lib.optionalAttrs (! args?system) {
# Allow system to be set modularly in nixpkgs.system.
# We set it to null, to remove the "legacy" entrypoint's
# non-hermetic default.
system = null;
}
);
});
And nixos/lib/eval-config.nix
is a wrapper of lib.evalModules
:
# Ideally eval-config.nix would be an extremely thin wrapper
# around lib.evalModules, so that modular systems that have nixos configs
# as subcomponents (e.g. the container feature, or nixops if network
# expressions are ever made modular at the top level) can just use
# types.submodule instead of using eval-config.nix
Closing this issue due to inactivity. Feel free to reopen if you are still have questions.
Still trying to wrap my head around it, but you've made it clear. Thank you!