mirror of
https://codeberg.org/privacy1st/nix-git
synced 2024-11-23 22:19:33 +01:00
docs: add example module
This commit is contained in:
parent
045858b536
commit
d2aafab2bf
49
examples/module.nix
Normal file
49
examples/module.nix
Normal 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".
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user