From b5d5afd99a7ff24de036885364f7a7bbe90dd405 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 23 Oct 2013 18:21:15 +0200 Subject: [PATCH] Allow modules to define warnings to be shown during evaluation --- nixos/modules/misc/assertions.nix | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/nixos/modules/misc/assertions.nix b/nixos/modules/misc/assertions.nix index 7ded9785bc1..229f8f27860 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 "warning: ${w}" 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)}"); };