From 13e949996dd18f6bd20c6251f5f5ddb5a20a574e Mon Sep 17 00:00:00 2001
From: Your Name <you@example.com>
Date: Sun, 3 Apr 2022 17:26:31 +0000
Subject: [PATCH] Deploiement 2048 bis ; debug staticWebsites.location

---
 hosts/hackens-org/2048.nix                   |  4 +-
 hosts/hackens-org/modules/default.nix        |  4 +-
 hosts/hackens-org/modules/staticWebsites.nix | 42 ++++++++++----------
 hosts/hackens-org/modules/webhooks.nix       |  5 ++-
 hosts/hackens-org/test-static.nix            |  2 +-
 hosts/hackens-org/wiki.nix                   |  4 +-
 6 files changed, 32 insertions(+), 29 deletions(-)

diff --git a/hosts/hackens-org/2048.nix b/hosts/hackens-org/2048.nix
index 7de6c21..652d11f 100644
--- a/hosts/hackens-org/2048.nix
+++ b/hosts/hackens-org/2048.nix
@@ -1,12 +1,12 @@
 { config, pkgs, ... }:
 {
-  staticWebsites.sites = {
+  services.staticWebsites.sites = {
     "2048" = {
       root = pkgs.fetchFromGitHub {
         owner = "hackEns";
         repo = "2048NdS";
         rev = "1df6db154ca22c380eb52844c7a6a7f888fb5610";
-        sha256 = "087471kpbpcg5920wy6fgcx6jz613zbyy0jn5iiimwjk1im1wa4q";
+        sha256 = "1y2v637j0g03g4l80ag72pm9kc46f07npir7ddp8i6x15bzygj1a";
       };
       hostname = config.my.subZone;
       location = "/2048";
diff --git a/hosts/hackens-org/modules/default.nix b/hosts/hackens-org/modules/default.nix
index e1ff977..8a5e678 100644
--- a/hosts/hackens-org/modules/default.nix
+++ b/hosts/hackens-org/modules/default.nix
@@ -2,8 +2,8 @@
 {
   imports = [
     ./my.nix
-    ./staticWebsite.nix
+    ./staticWebsites.nix
     ./nginx.nix
-    ./webhook.nix
+    ./webhooks.nix
   ];
 }
diff --git a/hosts/hackens-org/modules/staticWebsites.nix b/hosts/hackens-org/modules/staticWebsites.nix
index fa12992..d0858d3 100644
--- a/hosts/hackens-org/modules/staticWebsites.nix
+++ b/hosts/hackens-org/modules/staticWebsites.nix
@@ -36,27 +36,29 @@ in
   config = mkIf (eachSite != {}) {
     services.nginx = {
       enable = true;
-      virtualHosts = mapAttrs ( hostName: conf: (mkMerge [
-        {
-          serverName = conf.hostname;
-          forceSSL = if debug then false else true;
-          enableACME = if debug then false else true;
-        }
-
-        (mkIf (conf.location == null) {
-          root = conf.root;
-        })
-
-        (mkIf (conf.location != null) {
-          location = {
-            "~ ^${conf.location}" = {
-              alias = conf.root;
+      virtualHosts = mapAttrs' ( hostname: conf: {
+        name = conf.hostname;
+        value = (mkMerge [
+          {
+            serverName = conf.hostname;
+            forceSSL = if config.services.staticWebsites.debug then false else true;
+            enableACME = if config.services.staticWebsites.debug then false else true;
+          }
+  
+          (mkIf (conf.location == null) {
+            root = conf.root;
+          })
+  
+          (mkIf (conf.location != null) {
+            locations = {
+              "${conf.location}/" = {
+                alias = "${conf.root}/";
+              };
             };
-          };
-        })
-
-        ])
-      ) eachSite;
+          })
+  
+          ]);
+        }) eachSite;
     };
   };
 }
diff --git a/hosts/hackens-org/modules/webhooks.nix b/hosts/hackens-org/modules/webhooks.nix
index d83664d..d3e87b8 100644
--- a/hosts/hackens-org/modules/webhooks.nix
+++ b/hosts/hackens-org/modules/webhooks.nix
@@ -2,7 +2,7 @@
 with lib;
 let
   json = pkgs.formats.json {};
-  cfg = config.services.webhook;
+  cfg = config.services.webhooks;
 in
 {
   options.services.webhooks = {
@@ -33,6 +33,7 @@ in
     debug = mkOption {
       type = types.bool;
       default = false;
+    };
   };
   config = mkIf cfg.enable {
     services.nginx = {
@@ -50,6 +51,6 @@ in
       };
       script = "${cfg.package}/bin/webhook -nopanic -ip \"127.0.0.1\" -port \"${toString cfg.internalPort}\" -verbose -hooks ${json.generate "conf.json" cfg.hooks}";
       wantedBy = [ "mulit-user.target" ];
-   };
+    };
   };
 }
diff --git a/hosts/hackens-org/test-static.nix b/hosts/hackens-org/test-static.nix
index bb61648..6faa509 100644
--- a/hosts/hackens-org/test-static.nix
+++ b/hosts/hackens-org/test-static.nix
@@ -1,6 +1,6 @@
 { config, pkgs, ... }:
 {
-  services.staticWebsites.test = {
+  services.staticWebsites.sites.test = {
     hostname = "test.${config.my.subZone}";
     root = pkgs.writeTextDir "index.html" "Hello world!";
   };
diff --git a/hosts/hackens-org/wiki.nix b/hosts/hackens-org/wiki.nix
index d2c3051..e9b40f2 100644
--- a/hosts/hackens-org/wiki.nix
+++ b/hosts/hackens-org/wiki.nix
@@ -1,8 +1,8 @@
-{ pkgs, ... }:
+{ pkgs, config, ... }:
 {
   networking.firewall.allowedTCPPorts = [ 80 443 ];
   # TODO: move to hackens.org
-  services.dokuwiki.sites."hackens.ens.fr" = {
+  services.dokuwiki.sites."${config.my.subZone}" = {
     enable = true;
 
     extraConfig = ''