From 8b3b91344abe6b6361b22943a0176e41fb2d585c Mon Sep 17 00:00:00 2001
From: notgne2
Date: Mon, 26 Oct 2020 11:29:01 -0700
Subject: Improve checks usage, add check for activation script existing

---
 flake.nix | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/flake.nix b/flake.nix
index 73aa802..fe24754 100644
--- a/flake.nix
+++ b/flake.nix
@@ -34,7 +34,7 @@
           program = "${self.defaultPackage."${system}"}/bin/deploy";
         };
 
-        lib = {
+        lib = rec {
           setActivate = base: activate: pkgs.buildEnv {
             name = ("activatable-" + base.name);
             paths = [
@@ -51,8 +51,26 @@
             ];
           };
 
-          checkSchema = deploy: pkgs.runCommandNoCC "jsonschema-deploy-system" { }
-            "${pkgs.python3.pkgs.jsonschema}/bin/jsonschema -i ${pkgs.writeText "deploy.json" (builtins.toJSON deploy)} ${./interface/deploy.json} && touch $out";
+          # DEPRECATED
+          checkSchema = checks.schema;
+
+          deployChecks = deploy: builtins.mapAttrs (_: check: check deploy) checks;
+
+          checks = {
+            schema = deploy: pkgs.runCommandNoCC "jsonschema-deploy-system" { } ''
+              ${pkgs.python3.pkgs.jsonschema}/bin/jsonschema -i ${pkgs.writeText "deploy.json" (builtins.toJSON deploy)} ${./interface/deploy.json} && touch $out
+            '';
+
+            activate = deploy:
+              let
+                allPaths = pkgs.lib.flatten (pkgs.lib.mapAttrsToList (nodeName: node: pkgs.lib.mapAttrsToList (profileName: profile: profile.path) node.profiles) deploy.nodes);
+              in
+              pkgs.runCommandNoCC "deploy-rs-check-activate" { } ''
+                for i in ${builtins.concatStringsSep " " allPaths}; do test -f "$i/deploy-rs-activate" || (echo "A profile path is missing an activation script" && exit 1); done
+
+                touch $out
+              '';
+          };
         };
       });
 }
-- 
cgit v1.2.3