diff options
Diffstat (limited to 'nixos/modules/misc/assertions.nix')
-rw-r--r-- | nixos/modules/misc/assertions.nix | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/nixos/modules/misc/assertions.nix b/nixos/modules/misc/assertions.nix index 7ded9785bc10..229f8f278608 100644 --- a/nixos/modules/misc/assertions.nix +++ b/nixos/modules/misc/assertions.nix @@ -6,6 +6,8 @@ let failed = map (x: x.message) (filter (x: !x.assertion) config.assertions); + showWarnings = res: fold (w: x: builtins.trace "[1;31mwarning: ${w}[0m" x) res config.warnings; + in { @@ -24,14 +26,26 @@ in ''; }; + warnings = mkOption { + internal = true; + default = []; + type = types.listOf types.string; + example = [ "The `foo' service is deprecated and will go away soon!" ]; + description = '' + This option allows modules to show warnings to users during + the evaluation of the system configuration. + ''; + }; + }; config = { - # This option is evaluated always. Thus the assertions are checked as well. hacky! - environment.systemPackages = + # This option is evaluated always. Thus the assertions are checked + # as well. Hacky! + environment.systemPackages = showWarnings ( if [] == failed then [] - else throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failed)}"; + else throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failed)}"); }; |