forked from zentralwerk/network
lib/config: implement assertions and warnings
This commit is contained in:
parent
fe673209c6
commit
71675556f2
|
@ -13,6 +13,10 @@ let
|
||||||
{ lib, ... }:
|
{ lib, ... }:
|
||||||
with lib;
|
with lib;
|
||||||
{
|
{
|
||||||
|
options.assertions = mkOption {
|
||||||
|
type = with types; listOf unspecified;
|
||||||
|
internal = true;
|
||||||
|
};
|
||||||
options.warnings = mkOption {
|
options.warnings = mkOption {
|
||||||
type = types.listOf types.str;
|
type = types.listOf types.str;
|
||||||
default = [];
|
default = [];
|
||||||
|
@ -30,5 +34,33 @@ let
|
||||||
./legacy.nix
|
./legacy.nix
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
inherit (result) config;
|
||||||
|
|
||||||
|
warn = result:
|
||||||
|
if builtins.length config.warnings > 0
|
||||||
|
then builtins.trace ''
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
${self.lib.concatStringsSep "\n" config.warnings}
|
||||||
|
'' result
|
||||||
|
else result;
|
||||||
|
|
||||||
|
error = result:
|
||||||
|
let
|
||||||
|
failed =
|
||||||
|
builtins.filter ({ assertion, ... }: !assertion)
|
||||||
|
config.assertions;
|
||||||
|
in
|
||||||
|
if failed != []
|
||||||
|
then throw ''
|
||||||
|
Errors:
|
||||||
|
|
||||||
|
${self.lib.concatMapStringsSep "\n" ({ message, ... }: message) failed}
|
||||||
|
''
|
||||||
|
else result;
|
||||||
in
|
in
|
||||||
result.config
|
warn (
|
||||||
|
error (
|
||||||
|
builtins.removeAttrs config [ "assertions" "warnings" "gpgKey" "salt-pillar" ]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
|
@ -524,4 +524,9 @@ in
|
||||||
(reportCollisions "IPv4 subnet" (x: if x.subnet4 == null then [] else [x.subnet4]) config.site.net) ++
|
(reportCollisions "IPv4 subnet" (x: if x.subnet4 == null then [] else [x.subnet4]) config.site.net) ++
|
||||||
(reportCollisions "IPv6 subnet" (x: builtins.attrValues x.subnets6) config.site.net) ++
|
(reportCollisions "IPv6 subnet" (x: builtins.attrValues x.subnets6) config.site.net) ++
|
||||||
ospfUpstreamXorGw;
|
ospfUpstreamXorGw;
|
||||||
|
|
||||||
|
config.assertions = map (name: {
|
||||||
|
assertion = ! config.site.net ? ${name};
|
||||||
|
message = "Host \"${name}\" must be named differently if net \"${name}\" exists.";
|
||||||
|
}) (builtins.attrNames config.site.hosts);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue