lib.modules: Change class declaration in module to _class

This commit is contained in:
Robert Hensing
2023-04-17 20:14:07 +02:00
parent 7459c02495
commit fd88c79418
5 changed files with 11 additions and 11 deletions

View File

@@ -30,7 +30,7 @@ This is in contrast to `config._module.args`, which is only available after all
#### `class` {#module-system-lib-evalModules-param-class} #### `class` {#module-system-lib-evalModules-param-class}
If the `class` attribute is set and non-`null`, the module system will reject `imports` with a different `class`. If the `class` attribute is set and non-`null`, the module system will reject `imports` with a different `_class` declaration.
The `class` value should be a string in lower [camel case](https://en.wikipedia.org/wiki/Camel_case). The `class` value should be a string in lower [camel case](https://en.wikipedia.org/wiki/Camel_case).

View File

@@ -371,10 +371,10 @@ let
if class != null if class != null
then then
m: m:
if m.class != null -> m.class == class if m._class != null -> m._class == class
then m then m
else else
throw "The module ${m._file or m.key} was imported into ${class} instead of ${m.class}." throw "The module ${m._file or m.key} was imported into ${class} instead of ${m._class}."
else else
m: m; m: m;
@@ -475,28 +475,28 @@ let
else config; else config;
in in
if m ? config || m ? options then if m ? config || m ? options then
let badAttrs = removeAttrs m ["_file" "key" "disabledModules" "imports" "options" "config" "meta" "freeformType" "class"]; in let badAttrs = removeAttrs m ["_class" "_file" "key" "disabledModules" "imports" "options" "config" "meta" "freeformType"]; in
if badAttrs != {} then if badAttrs != {} then
throw "Module `${key}' has an unsupported attribute `${head (attrNames badAttrs)}'. This is caused by introducing a top-level `config' or `options' attribute. Add configuration attributes immediately on the top level instead, or move all of them (namely: ${toString (attrNames badAttrs)}) into the explicit `config' attribute." throw "Module `${key}' has an unsupported attribute `${head (attrNames badAttrs)}'. This is caused by introducing a top-level `config' or `options' attribute. Add configuration attributes immediately on the top level instead, or move all of them (namely: ${toString (attrNames badAttrs)}) into the explicit `config' attribute."
else else
{ _file = toString m._file or file; { _file = toString m._file or file;
_class = m._class or null;
key = toString m.key or key; key = toString m.key or key;
disabledModules = m.disabledModules or []; disabledModules = m.disabledModules or [];
imports = m.imports or []; imports = m.imports or [];
options = m.options or {}; options = m.options or {};
config = addFreeformType (addMeta (m.config or {})); config = addFreeformType (addMeta (m.config or {}));
class = m.class or null;
} }
else else
# shorthand syntax # shorthand syntax
lib.throwIfNot (isAttrs m) "module ${file} (${key}) does not look like a module." lib.throwIfNot (isAttrs m) "module ${file} (${key}) does not look like a module."
{ _file = toString m._file or file; { _file = toString m._file or file;
_class = m._class or null;
key = toString m.key or key; key = toString m.key or key;
disabledModules = m.disabledModules or []; disabledModules = m.disabledModules or [];
imports = m.require or [] ++ m.imports or []; imports = m.require or [] ++ m.imports or [];
options = {}; options = {};
config = addFreeformType (removeAttrs m ["_file" "key" "disabledModules" "require" "imports" "freeformType"]); config = addFreeformType (removeAttrs m ["_class" "_file" "key" "disabledModules" "require" "imports" "freeformType"]);
class = null;
}; };
applyModuleArgsIfFunction = key: f: args@{ config, options, lib, ... }: applyModuleArgsIfFunction = key: f: args@{ config, options, lib, ... }:

View File

@@ -63,14 +63,14 @@
modules = [ modules = [
./module-class-is-nixos.nix ./module-class-is-nixos.nix
{ _file = "foo.nix#darwinModules.default"; { _file = "foo.nix#darwinModules.default";
class = "darwin"; _class = "darwin";
config = {}; config = {};
imports = []; imports = [];
} }
]; ];
}; };
sub.nixosOk = { config = {}; class = "nixos"; }; sub.nixosOk = { _class = "nixos"; };
sub.nixosFail = { imports = [ ./module-class-is-darwin.nix ]; }; sub.nixosFail = { imports = [ ./module-class-is-darwin.nix ]; };
}; };
} }

View File

@@ -1,4 +1,4 @@
{ {
class = "darwin"; _class = "darwin";
config = {}; config = {};
} }

View File

@@ -1,4 +1,4 @@
{ {
class = "nixos"; _class = "nixos";
config = {}; config = {};
} }