From 1b1fc6550559f9d73ddf7cea611c387a847bf03b Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 11 Sep 2017 18:12:50 +0200 Subject: [PATCH] NixOS Manual: document assertions and warnings (#29206) * NixOS Manual: document assertions and warnings * NixOS manual: re-wrap assertions text --- nixos/doc/manual/configuration/summary.xml | 3 +- nixos/doc/manual/development/assertions.xml | 80 +++++++++++++++++++ .../manual/development/writing-modules.xml | 1 + 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 nixos/doc/manual/development/assertions.xml diff --git a/nixos/doc/manual/configuration/summary.xml b/nixos/doc/manual/configuration/summary.xml index 6ff0390c0ed..be1f2263149 100644 --- a/nixos/doc/manual/configuration/summary.xml +++ b/nixos/doc/manual/configuration/summary.xml @@ -113,7 +113,8 @@ manual for the rest. assert 1 + 1 == 2; "yes!" - Assertion check (evaluates to "yes!") + Assertion check (evaluates to "yes!"). See for using assertions in modules let x = "foo"; y = "bar"; in x + y diff --git a/nixos/doc/manual/development/assertions.xml b/nixos/doc/manual/development/assertions.xml new file mode 100644 index 00000000000..d3434e1f112 --- /dev/null +++ b/nixos/doc/manual/development/assertions.xml @@ -0,0 +1,80 @@ +
+ +Warnings and Assertions + + + When configuration problems are detectable in a module, it is a good + idea to write an assertion or warning. Doing so provides clear + feedback to the user and prevents errors after the build. + + + + Although Nix has the abort and + builtins.trace functions to perform such tasks, + they are not ideally suited for NixOS modules. Instead of these + functions, you can declare your warnings and assertions using the + NixOS module system. + + +
+ +Warnings + + + This is an example of using warnings. + + + + + + +
+ +
+ +Assertions + + + + This example, extracted from the + + syslogd module + shows how to use assertions. Since there + can only be one active syslog daemon at a time, an assertion is useful to + prevent such a broken system from being built. + + + + + + +
+ +
diff --git a/nixos/doc/manual/development/writing-modules.xml b/nixos/doc/manual/development/writing-modules.xml index 5bdcad5ceb5..cb363b45675 100644 --- a/nixos/doc/manual/development/writing-modules.xml +++ b/nixos/doc/manual/development/writing-modules.xml @@ -178,6 +178,7 @@ in { +