lol

fixup! doc: Add Module System chapter start

+30 -16
+30 -16
doc/module-system/module-system.chapter.md
··· 6 6 7 7 Compared to plain Nix, it adds documentation, type checking and composition or extensibility. 8 8 9 - NOTE: This chapter is new and not complete yet. For a gentle introduction to the module system, in the context of NixOS, see [Writing NixOS Modules](https://nixos.org/manual/nixos/unstable/index.html#sec-writing-modules) in the NixOS manual. 9 + ::: {.note} 10 + This chapter is new and not complete yet. For a gentle introduction to the module system, in the context of NixOS, see [Writing NixOS Modules](https://nixos.org/manual/nixos/unstable/index.html#sec-writing-modules) in the NixOS manual. 11 + ::: 12 + 10 13 11 14 ## `lib.evalModules` {#module-system-lib-evalModules} 12 15 13 - Evaluate a set of modules. The result is a set with the attributes: 16 + Evaluate a set of modules. This function is typically only used once per application (e.g. once in NixOS, once in Home Manager, ...). 14 17 15 18 ### Parameters {#module-system-lib-evalModules-parameters} 16 19 17 20 #### `modules` {#module-system-lib-evalModules-param-modules} 18 21 19 - A list of modules. These are merged together using various methods to form the final configuration. 22 + A list of modules. These are merged together to form the final configuration. 23 + <!-- TODO link to section about merging, TBD --> 20 24 21 25 #### `specialArgs` {#module-system-lib-evalModules-param-specialArgs} 22 26 23 27 An attribute set of module arguments that can be used in `imports`. 24 28 25 - This is in contrast to `config._module.args`, which is only available within the module fixpoint, which does not exist before all imports are resolved. 29 + This is in contrast to `config._module.args`, which is only available after all `imports` have been resolved. 26 30 27 31 #### `specialArgs.class` {#module-system-lib-evalModules-param-specialArgs-class} 28 32 29 - If the `class` attribute is set in `specialArgs`, the module system will rejected modules with a different `class`. 33 + If the `class` attribute is set in `specialArgs`, the module system will reject modules with a different `class`. 30 34 31 - This improves the error message that users will encounter when they import an incompatible module that was designed for a different class of configurations. 35 + The `class` value should be in lower [camel case](https://en.wikipedia.org/wiki/Camel_case). 32 36 33 - The `class` value should be in camelcase, and, if applicable, it should match the prefix of the attributes used in (experimental) flakes. Some examples are: 37 + If 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: 34 38 35 - - `nixos`: NixOS modules 39 + - `nixos` as in `flake.nixosModules` 36 40 - `nixosTest`: modules that constitute a [NixOS VM test](https://nixos.org/manual/nixos/stable/index.html#sec-nixos-tests) 41 + <!-- We've only just started with `class`. You're invited to add a few more. --> 37 42 38 43 #### `prefix` {#module-system-lib-evalModules-param-prefix} 39 44 40 45 A list of strings representing the location at or below which all options are evaluated. This is used by `types.submodule` to improve error reporting and find the implicit `name` module argument. 41 46 42 47 ### Return value {#module-system-lib-evalModules-return-value} 48 + 49 + The result is an attribute set with the following attributes: 43 50 44 51 #### `options` {#module-system-lib-evalModules-return-value-options} 45 52 46 - The nested set of all option declarations. 53 + The nested attribute set of all option declarations. 47 54 48 55 #### `config` {#module-system-lib-evalModules-return-value-config} 49 56 50 - The nested set of all option values. 57 + The nested attribute set of all option values. 51 58 52 59 #### `type` {#module-system-lib-evalModules-return-value-type} 53 60 54 - A module system type representing the module set as a submodule, to be extended by configuration from the containing module set. 61 + A module system type. This type is an instance of `types.submoduleWith` containing the current [`modules`](#module-system-lib-evalModules-param-modules). 55 62 56 - This is also available as the module argument `moduleType`. 63 + The option definitions that are typed with this type will extend the current set of modules, like [`extendModules`](#module-system-lib-evalModules-return-value-extendModules). 64 + 65 + However, the value returned from the type is just the [`config`](#module-system-lib-evalModules-return-value-config), like any submodule. 66 + 67 + This type is also available to the [`modules`](#module-system-lib-evalModules-param-modules) as the module argument `moduleType`. 57 68 58 69 #### `extendModules` {#module-system-lib-evalModules-return-value-extendModules} 59 70 60 - A function similar to `evalModules` but building on top of the module set. Its arguments, `modules` and `specialArgs` are added to the existing values. 71 + A function similar to `evalModules` but building on top of the already passed [`modules`](#module-system-lib-evalModules-param-modules). Its arguments, `modules` and `specialArgs` are added to the existing values. 61 72 62 - Using `extendModules` a few times has no performance impact as long as you only reference the final `options` and `config`. 63 - If you do reference multiple `config` (or `options`) from before and after `extendModules`, performance is the same as with multiple `evalModules` invocations, because the new modules' ability to override existing configuration fundamentally requires a new fixpoint to be constructed. 73 + The real work of module evaluation happens while computing the values in `config` and `options`, so multiple invocations of `extendModules` have a particularly small cost, as long as only the final `config` and `options` are evaluated. 74 + 75 + If you do reference multiple `config` (or `options`) from before and after `extendModules`, evaluation performance is the same as with multiple `evalModules` invocations, because the new modules' ability to override existing configuration fundamentally requires constructing a new `config` and `options` fixpoint. 64 76 65 - This is also available as a module argument. 77 + This functionality is also available to modules as the `extendModules` module argument. 66 78 67 79 #### `_module` {#module-system-lib-evalModules-return-value-_module} 68 80 69 81 A portion of the configuration tree which is elided from `config`. It contains some values that are mostly internal to the module system implementation. 82 + 83 + <!-- TODO: when markdown migration is complete, make _module docs visible again and reference _module docs. Maybe move those docs into this chapter? -->