about summary refs log tree commit diff
path: root/lib/modules.nix
diff options
context:
space:
mode:
authorSilvan Mosberger <contact@infinisil.com>2020-09-02 15:43:16 +0200
committerSilvan Mosberger <contact@infinisil.com>2020-11-30 23:51:23 +0100
commit20131348db3b51f7fe41f2d4aa3cd8875a6b48f2 (patch)
tree67aee1963d8de3ed8edf95fd2a68e8887ba5050c /lib/modules.nix
parent9523df7eb600e7fc2a88bc5227d9dfe12055a9bd (diff)
lib/modules: Use module-builtin assertions for mkRemovedOptionModule and co.
Diffstat (limited to 'lib/modules.nix')
-rw-r--r--lib/modules.nix38
1 files changed, 24 insertions, 14 deletions
diff --git a/lib/modules.nix b/lib/modules.nix
index 31200ae0b035c..1902db5c6167a 100644
--- a/lib/modules.nix
+++ b/lib/modules.nix
@@ -924,14 +924,16 @@ rec {
         visible = false;
         apply = x: throw "The option `${showOption optionName}' can no longer be used since it's been removed. ${replacementInstructions}";
       });
-      config.assertions =
-        let opt = getAttrFromPath optionName options; in [{
-          assertion = !opt.isDefined;
+      config._module.assertions =
+        let opt = getAttrFromPath optionName options; in {
+        ${showOption optionName} = {
+          enable = mkDefault opt.isDefined;
           message = ''
             The option definition `${showOption optionName}' in ${showFiles opt.files} no longer has any effect; please remove it.
             ${replacementInstructions}
           '';
-        }];
+        };
+      };
     };
 
   /* Return a module that causes a warning to be shown if the
@@ -992,14 +994,19 @@ rec {
       })) from);
 
       config = {
-        warnings = filter (x: x != "") (map (f:
-          let val = getAttrFromPath f config;
-              opt = getAttrFromPath f options;
-          in
-          optionalString
-            (val != "_mkMergedOptionModule")
-            "The option `${showOption f}' defined in ${showFiles opt.files} has been changed to `${showOption to}' that has a different type. Please read `${showOption to}' documentation and update your configuration accordingly."
-        ) from);
+        _module.assertions =
+          let warningMessages = map (f:
+            let val = getAttrFromPath f config;
+                opt = getAttrFromPath f options;
+            in {
+              ${showOption f} = {
+                enable = mkDefault (val != "_mkMergedOptionModule");
+                type = "warning";
+                message = "The option `${showOption f}' defined in ${showFiles opt.files} has been changed to `${showOption to}' that has a different type. Please read `${showOption to}' documentation and update your configuration accordingly.";
+              };
+            }
+            ) from;
+          in mkMerge warningMessages;
       } // setAttrByPath to (mkMerge
              (optional
                (any (f: (getAttrFromPath f config) != "_mkMergedOptionModule") from)
@@ -1058,8 +1065,11 @@ rec {
       });
       config = mkMerge [
         {
-          warnings = optional (warn && fromOpt.isDefined)
-            "The option `${showOption from}' defined in ${showFiles fromOpt.files} has been renamed to `${showOption to}'.";
+          _module.assertions.${showOption from} = {
+            enable = mkDefault (warn && fromOpt.isDefined);
+            type = "warning";
+            message = "The option `${showOption from}' defined in ${showFiles fromOpt.files} has been renamed to `${showOption to}'.";
+          };
         }
         (if withPriority
           then mkAliasAndWrapDefsWithPriority (setAttrByPath to) fromOpt