1# Warnings and Assertions {#sec-assertions} 2 3When 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. 4 5Although Nix has the `abort` and `builtins.trace` [functions](https://nixos.org/nix/manual/#ssec-builtins) 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. 6 7## Warnings {#sec-assertions-warnings} 8 9This is an example of using `warnings`. 10 11```nix 12{ config, lib, ... }: 13{ 14 config = lib.mkIf config.services.foo.enable { 15 warnings = 16 if config.services.foo.bar 17 then [ ''You have enabled the bar feature of the foo service. 18 This is known to cause some specific problems in certain situations. 19 '' ] 20 else []; 21 }; 22} 23``` 24 25## Assertions {#sec-assertions-assetions} 26 27This example, extracted from the [`syslogd` module](https://github.com/NixOS/nixpkgs/blob/release-17.09/nixos/modules/services/logging/syslogd.nix) 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. 28 29```nix 30{ config, lib, ... }: 31{ 32 config = lib.mkIf config.services.syslogd.enable { 33 assertions = 34 [ { assertion = !config.services.rsyslogd.enable; 35 message = "rsyslogd conflicts with syslogd"; 36 } 37 ]; 38 }; 39} 40```