summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--module.nix47
1 files changed, 30 insertions, 17 deletions
diff --git a/module.nix b/module.nix
index 574ae9b..f09fe3f 100644
--- a/module.nix
+++ b/module.nix
@@ -6,6 +6,8 @@ let
     ${text}
   '';
 
+  # -------- implementation -------- #
+
   cfg = config;
 
   logNames = flatten (mapAttrsToList (_: sv: optional (sv.log != null) sv.log) cfg.longruns);
@@ -137,8 +139,35 @@ let
   compiledDatabase = pkgs.runCommand "s6-rc-compiled-database" { } ''
     ${pkgs.s6-rc}/bin/s6-rc-compile $out ${serviceSourceDir}
   '';
+
+  # -------- assertions -------- #
+
+  assertions = [
+    {
+      assertion = length (attrNames allDefinitionDirs)
+        == length (attrNames cfg.bundles)
+        + length (attrNames cfg.oneshots)
+        + length (attrNames cfg.longruns)
+        + length (attrNames logLongruns);
+      message = "no two services can have the same name, even if they are of different types";
+    }
+  ] ++ mapAttrsToList
+    (name: def: {
+      assertion = def.producerFor == null || def.log == null;
+      message = "in `longruns.${name}`: `producerFor` and `log` are mutually exclusive";
+    })
+    cfg.longruns;
+
+  failedAssertions = map (x: x.message) (filter (x: !x.assertion) assertions);
+
+  checkAssertions =
+    if failedAssertions != [ ]
+    then throw "\nFailed assertions:\n${concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
+    else true;
 in
 {
+  # -------- interface -------- #
+
   options = with types;
     let
       mkNullableOption = { type, ... } @ o:
@@ -271,23 +300,7 @@ in
       };
     };
 
-  config = {
-    assertions = [
-      {
-        assertion = length (attrNames allDefinitionDirs)
-          == length (attrNames cfg.bundles)
-          + length (attrNames cfg.oneshots)
-          + length (attrNames cfg.longruns)
-          + length (attrNames logLongruns);
-        message = "no two services can have the same name, even if they are of different types";
-      }
-    ] ++ mapAttrsToList
-      (name: def: {
-        assertion = def.producerFor == null || def.log == null;
-        message = "in `longruns.${name}`: `producerFor` and `log` are mutually exclusive";
-      })
-      cfg.longruns;
-
+  config = lib.mkIf checkAssertions {
     inherit serviceSourceDir compiledDatabase;
   };
 }