summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalte Voos <malte@malvo.org>2022-05-13 17:38:39 +0200
committerMalte Voos <malte@malvo.org>2022-05-13 17:38:39 +0200
commit15605e3c728feedec5c3568dd2a9458d0b120c44 (patch)
tree1282d394b6d05c60be452ff8f4318af2878347e3
parent21dcea7bab133a440679a62e51bc44c24508a669 (diff)
downloads6-rc.nix-15605e3c728feedec5c3568dd2a9458d0b120c44.tar.gz
s6-rc.nix-15605e3c728feedec5c3568dd2a9458d0b120c44.zip
own assertions implementation
-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;
};
}