nixos/assertions: Use module-builtin assertion implementation

This commit is contained in:
Silvan Mosberger
2020-11-30 23:51:22 +01:00
parent df5ba82f74
commit 9523df7eb6
3 changed files with 27 additions and 16 deletions
+20 -1
View File
@@ -1,4 +1,4 @@
{ lib, ... }:
{ lib, config, ... }:
with lib;
@@ -29,6 +29,25 @@ with lib;
'';
};
_module.assertions = mkOption {
type = types.attrsOf (types.submodule {
triggerPath = mkDefault [ "system" "build" "toplevel" ];
});
};
};
config._module.assertions = lib.listToAttrs (lib.imap1 (n: value:
let
name = "_${toString n}";
isWarning = lib.isString value;
result = {
enable = if isWarning then true else ! value.assertion;
type = if isWarning then "warning" else "error";
message = if isWarning then value else value.message;
};
in nameValuePair name result
) (config.assertions ++ config.warnings));
# impl of assertions is in <nixpkgs/nixos/modules/system/activation/top-level.nix>
}