···28282929This is in contrast to `config._module.args`, which is only available after all `imports` have been resolved.
30303131-#### `specialArgs.class` {#module-system-lib-evalModules-param-specialArgs-class}
3131+#### `class` {#module-system-lib-evalModules-param-class}
32323333-If the `class` attribute is set in `specialArgs`, the module system will reject modules with a different `class`.
3333+If the `class` attribute is set and non-`null`, the module system will reject `imports` with a different `class`.
34343535-The `class` value should be in lower [camel case](https://en.wikipedia.org/wiki/Camel_case).
3535+The `class` value should be a string in lower [camel case](https://en.wikipedia.org/wiki/Camel_case).
36363737If applicable, the `class` should match the "prefix" of the attributes used in (experimental) [flakes](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#description). Some examples are:
3838
+19-7
lib/modules.nix
···7878 # when resolving module structure (like in imports). For everything else,
7979 # there's _module.args. If specialArgs.modulesPath is defined it will be
8080 # used as the base path for disabledModules.
8181- #
8282- # `specialArgs.class`:
8181+ specialArgs ? {}
8282+ , # `class`:
8383 # A nominal type for modules. When set and non-null, this adds a check to
8484 # make sure that only compatible modules are imported.
8585- specialArgs ? {}
8686- , # This would be remove in the future, Prefer _module.args option instead.
8787- args ? {}
8585+ # This would be remove in the future, Prefer _module.args option instead.
8686+ class ? null
8787+ , args ? {}
8888 , # This would be remove in the future, Prefer _module.check option instead.
8989 check ? true
9090 }:
···220220 within a configuration, but can be used in module imports.
221221 '';
222222 };
223223+224224+ _module.class = mkOption {
225225+ readOnly = true;
226226+ internal = true;
227227+ description = lib.mdDoc ''
228228+ If the `class` attribute is set and non-`null`, the module system will reject `imports` with a different `class`.
229229+230230+ This option contains the expected `class` attribute of the current module evaluation.
231231+ '';
232232+ };
223233 };
224234225235 config = {
···227237 inherit extendModules;
228238 moduleType = type;
229239 };
240240+ _module.class = class;
230241 _module.specialArgs = specialArgs;
231242 };
232243 };
233244234245 merged =
235246 let collected = collectModules
236236- (specialArgs.class or null)
247247+ class
237248 (specialArgs.modulesPath or "")
238249 (regularModules ++ [ internalModule ])
239250 ({ inherit lib options config specialArgs; } // specialArgs);
···310321 prefix ? [],
311322 }:
312323 evalModules (evalModulesArgs // {
324324+ inherit class;
313325 modules = regularModules ++ modules;
314326 specialArgs = evalModulesArgs.specialArgs or {} // specialArgs;
315327 prefix = extendArgs.prefix or evalModulesArgs.prefix or [];
316328 });
317329318330 type = lib.types.submoduleWith {
319319- inherit modules specialArgs;
331331+ inherit modules specialArgs class;
320332 };
321333322334 result = withWarnings {
···696696 , specialArgs ? {}
697697 , shorthandOnlyDefinesConfig ? false
698698 , description ? null
699699+ , class ? null
699700 }@attrs:
700701 let
701702 inherit (lib.modules) evalModules;
···707708 ) defs;
708709709710 base = evalModules {
710710- inherit specialArgs;
711711+ inherit class specialArgs;
711712 modules = [{
712713 # This is a work-around for the fact that some sub-modules,
713714 # such as the one included in an attribute set, expects an "args"
···762763 functor = defaultFunctor name // {
763764 type = types.submoduleWith;
764765 payload = {
765765- inherit modules specialArgs shorthandOnlyDefinesConfig description;
766766+ inherit modules class specialArgs shorthandOnlyDefinesConfig description;
766767 };
767768 binOp = lhs: rhs: {
769769+ class =
770770+ if lhs.class == null then rhs.class
771771+ else if rhs.class == null then lhs.class
772772+ else if lhs.class == rhs.class then lhs.class
773773+ else throw "A submoduleWith option is declared multiple times with conflicting class values \"${toString lhs.class}\" and \"${toString rhs.class}\".";
768774 modules = lhs.modules ++ rhs.modules;
769775 specialArgs =
770776 let intersecting = builtins.intersectAttrs lhs.specialArgs rhs.specialArgs;