olaf
August 5, 2022, 4:45pm
1
a configuration.nix is a module
modules have this structure
Example: Structure of NixOS Modules
{ config, pkgs, ... }:
{
imports =
[ paths of other modules
];
options = {
option declarations
};
config = {
option definitions
};
}
but why do we usually write
{ config, pkgs, ... }: {
users.users.alice.isNormalUser = true;
}
instead of
{ config, pkgs, ... }: {
config = { users.users.alice.isNormalUser = true; };
}
Is this syntactic sugar, backwards compatibility, both, neither or something completely different?
nrdxp
August 5, 2022, 4:55pm
2
syntactic sugar to avoid redundancy when one is simply wishing to set existing options instead of defining new ones.
2 Likes
olaf
August 5, 2022, 4:58pm
3
@nrdxp do you know where it is implemented?
nrdxp
August 5, 2022, 5:06pm
4
Not exactly, but likely somewhere in this beast:
‘_module’: A portion of the configuration tree which is elided from
‘config’. It contains some values that are mostly internal to the
module system implementation.
!!! Please think twice before adding to this argument list! The more
that is specified here instead of in the modules themselves the harder
it is to transparently move a set of modules to be a submodule of another
config (as the proper arguments need to be replicated at each call to
evalModules) and the less declarative the module set is. */
evalModules = evalModulesArgs@
{ modules
, prefix ? []
, # This should only be used for special arguments that need to be evaluated
# when resolving module structure (like in imports). For everything else,
# there's _module.args. If specialArgs.modulesPath is defined it will be
# used as the base path for disabledModules.
specialArgs ? {}
, # This would be remove in the future, Prefer _module.args option instead.
args ? {}
, # This would be remove in the future, Prefer _module.check option instead.
1 Like
It’s documented right above the example you gave:
This is actually an abbreviated form of module that only defines options, but does not declare any. The structure of full NixOS modules is shown in Example: Structure of NixOS Modules .
1 Like