Allow modules to define warnings to be shown during evaluation
This commit is contained in:
parent
6de7886fb8
commit
b5d5afd99a
|
@ -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)}");
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue