mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-17 19:21:04 +00:00
lib.modules: Change class declaration in module to _class
This commit is contained in:
parent
7459c02495
commit
fd88c79418
|
@ -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}
|
||||
|
||||
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).
|
||||
|
||||
|
|
|
@ -371,10 +371,10 @@ let
|
|||
if class != null
|
||||
then
|
||||
m:
|
||||
if m.class != null -> m.class == class
|
||||
if m._class != null -> m._class == class
|
||||
then m
|
||||
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
|
||||
m: m;
|
||||
|
||||
|
@ -475,28 +475,28 @@ let
|
|||
else config;
|
||||
in
|
||||
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
|
||||
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
|
||||
{ _file = toString m._file or file;
|
||||
_class = m._class or null;
|
||||
key = toString m.key or key;
|
||||
disabledModules = m.disabledModules or [];
|
||||
imports = m.imports or [];
|
||||
options = m.options or {};
|
||||
config = addFreeformType (addMeta (m.config or {}));
|
||||
class = m.class or null;
|
||||
}
|
||||
else
|
||||
# shorthand syntax
|
||||
lib.throwIfNot (isAttrs m) "module ${file} (${key}) does not look like a module."
|
||||
{ _file = toString m._file or file;
|
||||
_class = m._class or null;
|
||||
key = toString m.key or key;
|
||||
disabledModules = m.disabledModules or [];
|
||||
imports = m.require or [] ++ m.imports or [];
|
||||
options = {};
|
||||
config = addFreeformType (removeAttrs m ["_file" "key" "disabledModules" "require" "imports" "freeformType"]);
|
||||
class = null;
|
||||
config = addFreeformType (removeAttrs m ["_class" "_file" "key" "disabledModules" "require" "imports" "freeformType"]);
|
||||
};
|
||||
|
||||
applyModuleArgsIfFunction = key: f: args@{ config, options, lib, ... }:
|
||||
|
|
|
@ -63,14 +63,14 @@
|
|||
modules = [
|
||||
./module-class-is-nixos.nix
|
||||
{ _file = "foo.nix#darwinModules.default";
|
||||
class = "darwin";
|
||||
_class = "darwin";
|
||||
config = {};
|
||||
imports = [];
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
sub.nixosOk = { config = {}; class = "nixos"; };
|
||||
sub.nixosOk = { _class = "nixos"; };
|
||||
sub.nixosFail = { imports = [ ./module-class-is-darwin.nix ]; };
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
class = "darwin";
|
||||
_class = "darwin";
|
||||
config = {};
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
class = "nixos";
|
||||
_class = "nixos";
|
||||
config = {};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue