Allow modules to define warnings to be shown during evaluation

This commit is contained in:
Eelco Dolstra 2013-10-23 18:21:15 +02:00
parent 6de7886fb8
commit b5d5afd99a

View file

@ -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)}");
};