docs: add example module

This commit is contained in:
Daniel Langbein 2023-10-09 10:48:17 +02:00
parent 045858b536
commit d2aafab2bf
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002
2 changed files with 49 additions and 0 deletions

49
examples/module.nix Normal file
View File

@ -0,0 +1,49 @@
# https://nixos.wiki/wiki/NixOS_modules
# This module can be used as follows:
# {
# imports = [ ./module.nix ];
# services.example = {
# enable = true;
# message = "Hello :)";
# };
# }
{ lib, config, options, pkgs, modulesPath, ... }:
with lib;
let
# cfg is a typical convention.
cfg = config.services.example;
in
{
imports = [
# Paths to other modules.
# Compose this module out of smaller ones.
];
options = {
# Option declarations.
# Declare what settings a user of this module module can set.
# Usually this includes an "enable" option to let a user of this module choose.
services.example = {
enable = mkEnableOption "example service";
message = mkOption {
type = types.str;
default = "Hello, world!";
example = "Hi!";
# A textual description of the option, in DocBook format.
description = ''
You can set any message you want here.
'';
};
};
};
config = mkIf cfg.enable {
# Option definitions.
# Define what other settings, services and resources should be active.
# These are depend on whether a user of this module chose to "enable" it using the "option" above.
# You also set options here for modules that you imported in "imports".
};
}