Add a directive to add headers

We need this for our .well-known CORS, so I've also added a special
"CrossOrigin" directive to do exactly what we want

Change-Id: Ic80aba455e6b49a938ddfe24290b170f58a72f10
Reviewed-on: https://git.clicks.codes/c/Clicks/NixHelpers/+/30
Reviewed-by: Skyler Grey <minion@clicks.codes>
Tested-by: Skyler Grey <minion@clicks.codes>
diff --git a/nginx.nix b/nginx.nix
index f229dbf..bc43ad4 100644
--- a/nginx.nix
+++ b/nginx.nix
@@ -71,6 +71,16 @@
     inherit statusCode;
     type = "status";
   };
+  Header = header: value: service: {
+    inherit header value service;
+    type = "header";
+  };
+  CrossOrigin = service: {
+    inherit service;
+    header = "Access-Control-Allow-Origin";
+    value = "*";
+    type = "header";
+  };
 
   Merge = let
     # builtins.length and count up
@@ -160,6 +170,22 @@
       else if service.type == "path" then
         _merge service.service currentConfig service.path service.secure
         priority
+      else if service.type == "header" then
+        _merge service.service
+          (lib.recursiveUpdate currentConfig {
+          value.locations.${currentPath} = {
+            extraConfig =
+              (if
+                builtins.hasAttr "value" currentConfig
+                && builtins.hasAttr "locations" currentConfig.value
+                && builtins.hasAttr currentPath currentConfig.value.locations
+                && builtins.hasAttr "extraConfig" currentConfig.value.locations.${currentPath}
+              then currentConfig.value.locations.${currentPath}.extraConfig else "") +
+            ''
+              add_header ${service.header} "${service.value}";
+            '';
+          };
+        }) currentPath secure priority
       else if service.type == "compose" then
         (_iterateCompose service.services currentConfig currentPath secure
           priority 0)