summary refs log tree commit diff
path: root/nixos/modules/misc/assertions.nix
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2020-09-02 00:17:26 +0200
committerSilvan Mosberger <contact@infinisil.com>2020-11-30 23:51:22 +0100
commit9523df7eb600e7fc2a88bc5227d9dfe12055a9bd (patch)
tree64fb87e447b515e1b7ebbce0eeb32f3942d47947 /nixos/modules/misc/assertions.nix
parentdf5ba82f74df75e96390995472f3e1e5179da21c (diff)
downloadnixpkgs-9523df7eb600e7fc2a88bc5227d9dfe12055a9bd.tar
nixpkgs-9523df7eb600e7fc2a88bc5227d9dfe12055a9bd.tar.gz
nixpkgs-9523df7eb600e7fc2a88bc5227d9dfe12055a9bd.tar.bz2
nixpkgs-9523df7eb600e7fc2a88bc5227d9dfe12055a9bd.tar.lz
nixpkgs-9523df7eb600e7fc2a88bc5227d9dfe12055a9bd.tar.xz
nixpkgs-9523df7eb600e7fc2a88bc5227d9dfe12055a9bd.tar.zst
nixpkgs-9523df7eb600e7fc2a88bc5227d9dfe12055a9bd.zip
nixos/assertions: Use module-builtin assertion implementation
Diffstat (limited to 'nixos/modules/misc/assertions.nix')
-rw-r--r--nixos/modules/misc/assertions.nix21
1 files changed, 20 insertions, 1 deletions
diff --git a/nixos/modules/misc/assertions.nix b/nixos/modules/misc/assertions.nix
index 550b3ac97f6..e931611247f 100644
--- a/nixos/modules/misc/assertions.nix
+++ b/nixos/modules/misc/assertions.nix
@@ -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>
 }