NixOS modules: Difference between revisions
Removed redundant outdated text, that is linked to the manual. Also improved wording in the section. |
Added a short meta.doc description to the example |
||
| (4 intermediate revisions by the same user not shown) | |||
| Line 26: | Line 26: | ||
# using the "option" above. | # using the "option" above. | ||
# Options for modules imported in "imports" can be set here. | # Options for modules imported in "imports" can be set here. | ||
}; | |||
meta = { | |||
# Meta-attributes to provide extra information like documentation or maintainers. | |||
}; | }; | ||
} | } | ||
| Line 194: | Line 198: | ||
package = lib.options.mkPackageOption pkgs "bash" { }; | package = lib.options.mkPackageOption pkgs "bash" { }; | ||
# type = lib.types.package; | # type = lib.types.package; | ||
numberOfTheDay = lib.options.mkOption { | |||
type = lib.types.ints.between 50 100; | |||
default = 61; | |||
}; | |||
groceries = lib.options.mkOption { | groceries = lib.options.mkOption { | ||
| Line 207: | Line 216: | ||
settings = lib.options.mkOption { | settings = lib.options.mkOption { | ||
type = lib.types. | type = lib.types.toml; | ||
default = {}; | default = {}; | ||
description = '' | description = '' | ||
| Line 253: | Line 262: | ||
"unit1" = { unit = "m" }; | "unit1" = { unit = "m" }; | ||
"unit2".unit = "cm"; | "unit2".unit = "cm"; | ||
"unit3" = {}; # kg | |||
}; | }; | ||
}; | }; | ||
| Line 266: | Line 276: | ||
To see how modules are setup and reuse other modules in practice put <code>hello.nix</code> in the same folder as your <code>configuration.nix</code>: | To see how modules are setup and reuse other modules in practice put <code>hello.nix</code> in the same folder as your <code>configuration.nix</code>: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix">{ lib, pkgs, config, ... }: | ||
{ lib, pkgs, config, ... }: | |||
with lib; | with lib; | ||
let | let | ||
| Line 275: | Line 284: | ||
cfg = config.services.hello; | cfg = config.services.hello; | ||
in { | in { | ||
meta.doc = "Says hello every time you login."; | |||
# Declare what settings a user of this "hello.nix" module CAN SET. | # Declare what settings a user of this "hello.nix" module CAN SET. | ||
options.services.hello = { | options.services.hello = { | ||
| Line 293: | Line 304: | ||
}; | }; | ||
}; | }; | ||
} | }</syntaxhighlight> | ||
</syntaxhighlight> | |||
The other <code>configuration.nix</code> module can then import this <code>hello.nix</code> module | The other <code>configuration.nix</code> module can then import this <code>hello.nix</code> module | ||