]> git.immae.eu Git - perso/Immae/Config/Nix.git/commitdiff
Move webstats outside of nixops
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Sat, 11 May 2019 08:23:33 +0000 (10:23 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Sat, 11 May 2019 08:23:33 +0000 (10:23 +0200)
15 files changed:
modules/default.nix
modules/webapps/webstats/default.nix [moved from nixops/modules/websites/commons/stats.nix with 53% similarity]
modules/webapps/webstats/goaccess.conf [moved from nixops/modules/websites/commons/goaccess.conf with 100% similarity]
nixops/modules/websites/aten/default.nix
nixops/modules/websites/chloe/default.nix
nixops/modules/websites/connexionswing/default.nix
nixops/modules/websites/default.nix
nixops/modules/websites/ftp/denisejerome.nix
nixops/modules/websites/ftp/immae.nix
nixops/modules/websites/ftp/jerome.nix
nixops/modules/websites/ftp/leila.nix
nixops/modules/websites/ftp/nassime.nix
nixops/modules/websites/ftp/release.nix
nixops/modules/websites/ludivine/default.nix
nixops/modules/websites/piedsjaloux/default.nix

index c920a5158ec7bf7e3185962f94b71b364bd20598..2c993c56b76a996a4383d33d322f0140e83230b6 100644 (file)
@@ -2,6 +2,7 @@
   myids = ./myids.nix;
   secrets = ./secrets.nix;
 
+  webstats = ./webapps/webstats;
   diaspora = ./webapps/diaspora.nix;
   etherpad-lite = ./webapps/etherpad-lite.nix;
   mastodon = ./webapps/mastodon.nix;
similarity index 53%
rename from nixops/modules/websites/commons/stats.nix
rename to modules/webapps/webstats/default.nix
index 73595f1ff7e71838c5e0068ac68939cba239e04a..f4916bd011fc03ceb61e4b037a586937cb00e5cb 100644 (file)
@@ -1,27 +1,42 @@
 { lib, pkgs, config, mylibs, ... }:
 let
-    cfg = config.services.myWebsites.commons.stats;
+  name = "goaccess";
+  cfg = config.services.webstats;
 in {
-  options = {
-    services.myWebsites.commons.stats = {
-      enable = lib.mkEnableOption "enable statistics";
-      sites = lib.mkOption {
-        type = lib.types.listOf (lib.types.submodule {
-          options = {
-            conf = lib.mkOption {
-              type = lib.types.nullOr lib.types.path;
-              default = null;
-            };
-            name = lib.mkOption { type = lib.types.string; };
+  options.services.webstats = {
+    dataDir = lib.mkOption {
+      type = lib.types.path;
+      default = "/var/lib/${name}";
+      description = ''
+        The directory where Goaccess stores its data.
+      '';
+    };
+    sites = lib.mkOption {
+      type = lib.types.listOf (lib.types.submodule {
+        options = {
+          conf = lib.mkOption {
+            type = lib.types.nullOr lib.types.path;
+            default = null;
+            description = ''
+              use custom goaccess configuration file instead of the
+              default one.
+              '';
+          };
+          name = lib.mkOption {
+            type = lib.types.string;
+            description  = ''
+              Domain name. Corresponds to the Apache file name and the
+              folder name in which the state will be saved.
+              '';
           };
-        });
-        default = [];
-        description = "Sites to generate stats";
-      };
+        };
+      });
+      default = [];
+      description = "Sites to generate stats";
     };
   };
 
-  config = lib.mkIf cfg.enable {
+  config = lib.mkIf (builtins.length cfg.sites > 0) {
     users.users.root.packages = [
       pkgs.goaccess
     ];
@@ -32,7 +47,7 @@ in {
         stats = domain: conf: let
           config = if builtins.isNull conf
             then pkgs.runCommand "goaccess.conf" {
-                dbPath = "/var/lib/goaccess/${domain}";
+                dbPath = "${cfg.dataDir}/${domain}";
               } "substituteAll ${./goaccess.conf} $out"
             else conf;
           d = pkgs.writeScriptBin "stats-${domain}" ''
@@ -47,7 +62,7 @@ in {
             for i in /var/log/httpd/access_log-${domain}*.gz; do
               zcat "$i" | sed -n "/\\[$date_regex/ p" >> $TMPFILE
             done
-            ${pkgs.goaccess}/bin/goaccess $TMPFILE --no-progress -o /var/lib/goaccess/${domain}/index.html -p ${config}
+            ${pkgs.goaccess}/bin/goaccess $TMPFILE --no-progress -o ${cfg.dataDir}/${domain}/index.html -p ${config}
             '';
           in "${d}/bin/stats-${domain}";
         allStats = sites: pkgs.writeScript "stats" ''
@@ -64,6 +79,6 @@ in {
     system.activationScripts.goaccess = ''
       mkdir -p /var/lib/goaccess
     '' +
-    builtins.concatStringsSep "\n" (map (v: "mkdir -p /var/lib/goaccess/${v.name}") cfg.sites);
+    builtins.concatStringsSep "\n" (map (v: "mkdir -p ${cfg.dataDir}/${v.name}") cfg.sites);
   };
 }
index 5dff00866e04cc0798e34edf451d8fe547cc61b1..fd3f7ccaefefe0d4b615a5e787977dc9364a5564 100644 (file)
@@ -19,17 +19,10 @@ in {
     };
   };
 
-  imports = [
-    ../commons/stats.nix
-  ];
-
   config = lib.mkMerge [
     (lib.mkIf cfg.production.enable {
       secrets.keys = aten_prod.keys;
-      services.myWebsites.commons.stats.enable = true;
-      services.myWebsites.commons.stats.sites = [
-        { name = "aten.pro"; }
-      ];
+      services.webstats.sites = [ { name = "aten.pro"; } ];
 
       security.acme.certs."aten" = config.services.myCertificates.certConfig // {
         domain = "aten.pro";
index 898007704dbef6ad24057769cf8e8a1bc69f4b08..a542d70f8e15d5585b5edaf40191527f74857d8b 100644 (file)
@@ -19,17 +19,10 @@ in {
     };
   };
 
-  imports = [
-    ../commons/stats.nix
-  ];
-
   config = lib.mkMerge [
     (lib.mkIf cfg.production.enable {
       secrets.keys = chloe_prod.keys;
-      services.myWebsites.commons.stats.enable = true;
-      services.myWebsites.commons.stats.sites = [
-        { name = "osteopathe-cc.fr"; }
-      ];
+      services.webstats.sites = [ { name = "osteopathe-cc.fr"; } ];
 
       security.acme.certs."chloe" = config.services.myCertificates.certConfig // {
         domain = "osteopathe-cc.fr";
index 37426ddabf947225013f8801bd004be190dae34b..773c8de49dfded9a93ce1b2aecd9fef9ba05395c 100644 (file)
@@ -19,17 +19,10 @@ in {
     };
   };
 
-  imports = [
-    ../commons/stats.nix
-  ];
-
   config = lib.mkMerge [
     (lib.mkIf cfg.production.enable {
       secrets.keys = connexionswing_prod.keys;
-      services.myWebsites.commons.stats.enable = true;
-      services.myWebsites.commons.stats.sites = [
-        { name = "connexionswing.com"; }
-      ];
+      services.webstats.sites = [ { name = "connexionswing.com"; } ];
 
       security.acme.certs."connexionswing" = config.services.myCertificates.certConfig // {
         domain = "connexionswing.com";
index ceef1e187412f96506238430ba3b31636b9afe5a..79cd1a1b62b423a3c92e135ddfdffd3ffbbae6a1 100644 (file)
@@ -260,13 +260,13 @@ in
       stats = {
         extraConfig = ''
           <Macro Stats %{domain}>
-            Alias /awstats /var/lib/goaccess/%{domain}
-            <Directory /var/lib/goaccess/%{domain}>
+            Alias /webstats ${config.services.webstats.dataDir}/%{domain}
+            <Directory ${config.services.webstats.dataDir}/%{domain}>
               DirectoryIndex index.html
               AllowOverride None
               Require all granted
             </Directory>
-            <Location /awstats>
+            <Location /webstats>
               Use LDAPConnect
               Require ldap-group cn=%{domain},ou=stats,cn=httpd,ou=services,dc=immae,dc=eu
             </Location>
index f39e5c2a107a839051ef6b020416b6c5de472b4d..4069b46c05788d48d429e62142b4c02989947197 100644 (file)
@@ -10,15 +10,8 @@ in {
     };
   };
 
-  imports = [
-    ../commons/stats.nix
-  ];
-
   config = lib.mkIf cfg.production.enable {
-    services.myWebsites.commons.stats.enable = true;
-    services.myWebsites.commons.stats.sites = [
-      { name = "denisejerome.piedsjaloux.fr"; }
-    ];
+    services.webstats.sites = [ { name = "denisejerome.piedsjaloux.fr"; } ];
 
     security.acme.certs."denisejerome" = config.services.myCertificates.certConfig // {
       domain = "denisejerome.piedsjaloux.fr";
index 2ecca1fe764a8c44ce1f03f474c990ba32b1fdeb..d4e6d39c4f50419120d42675e6f97c511181985b 100644 (file)
@@ -10,15 +10,8 @@ in {
     };
   };
 
-  imports = [
-    ../commons/stats.nix
-  ];
-
   config = lib.mkIf cfg.production.enable {
-    services.myWebsites.commons.stats.enable = true;
-    services.myWebsites.commons.stats.sites = [
-      { name = "www.immae.eu"; }
-    ];
+    services.webstats.sites = [ { name = "www.immae.eu"; } ];
 
     security.acme.certs."eldiron".extraDomains."www.immae.eu" = null;
 
index e04d6408ebe6ce448cca25d86918f24514b81a1f..60e4dfba95ab52d43599d6a85a64cb44f2b6006e 100644 (file)
@@ -11,15 +11,8 @@ in {
     };
   };
 
-  imports = [
-    ../commons/stats.nix
-  ];
-
   config = lib.mkIf cfg.production.enable {
-    services.myWebsites.commons.stats.enable = true;
-    services.myWebsites.commons.stats.sites = [
-      { name = "naturaloutil.immae.eu"; }
-    ];
+    services.webstats.sites = [ { name = "naturaloutil.immae.eu"; } ];
 
     security.acme.certs."ftp".extraDomains."naturaloutil.immae.eu" = null;
     security.acme.certs."naturaloutil" = config.services.myCertificates.certConfig // {
index d5c27faadbf131906f01ec08f6e6dbef5e7213cd..c5c27b1a950231cd7e8e578d75650f5f5dc9b772 100644 (file)
@@ -9,10 +9,6 @@ in {
     };
   };
 
-  imports = [
-    ../commons/stats.nix
-  ];
-
   config = (lib.mkIf cfg.production.enable {
       security.acme.certs."leila" = config.services.myCertificates.certConfig // {
         domain = "leila.bouya.org";
@@ -37,8 +33,7 @@ in {
         php_admin_value[open_basedir] = "${varDir}:/tmp"
         '';
 
-      services.myWebsites.commons.stats.enable = true;
-      services.myWebsites.commons.stats.sites = [
+      services.webstats.sites = [
         { name = "leila.bouya.org"; }
         { name = "chorale.leila.bouya.org"; }
       ];
index d7ced7e69763b9709eef85884cddb6bdb3034301..f2950458f67aba78ea9549b7896c062255ddeb9f 100644 (file)
@@ -10,15 +10,8 @@ in {
     };
   };
 
-  imports = [
-    ../commons/stats.nix
-  ];
-
   config = lib.mkIf cfg.production.enable {
-    services.myWebsites.commons.stats.enable = true;
-    services.myWebsites.commons.stats.sites = [
-      { name = "nassime.bouya.org"; }
-    ];
+    services.webstats.sites = [ { name = "nassime.bouya.org"; } ];
 
     security.acme.certs."ftp".extraDomains."nassime.bouya.org" = null;
     security.acme.certs."nassime" = config.services.myCertificates.certConfig // {
index 2050a6c6a8867dd69f08f5ec007021902339c9cb..896691b7be8586c98adfc19b72ad3ce7da053ae8 100644 (file)
@@ -10,15 +10,8 @@ in {
     };
   };
 
-  imports = [
-    ../commons/stats.nix
-  ];
-
   config = lib.mkIf cfg.production.enable {
-    services.myWebsites.commons.stats.enable = true;
-    services.myWebsites.commons.stats.sites = [
-      { name = "release.immae.eu"; }
-    ];
+    services.webstats.sites = [ { name = "release.immae.eu"; } ];
 
     security.acme.certs."eldiron".extraDomains."release.immae.eu" = null;
 
index af18d71d93a6c454993aa946faec0a793edc7e72..2fcd94a424fd1395cb0ad5c034533681b74455e5 100644 (file)
@@ -22,10 +22,7 @@ in {
   config = lib.mkMerge [
     (lib.mkIf cfg.production.enable {
       secrets.keys = ludivinecassal_prod.keys;
-      services.myWebsites.commons.stats.enable = true;
-      services.myWebsites.commons.stats.sites = [
-        { name = "ludivinecassal.com"; }
-      ];
+      services.webstats.sites = [ { name = "ludivinecassal.com"; } ];
 
       security.acme.certs."ludivinecassal" = config.services.myCertificates.certConfig // {
         domain = "ludivinecassal.com";
index 165791416bf876583f1acb4190a1a9bb85bc4d6c..9f9697d26dc0c18ef0ff9d51045b32144d7de96f 100644 (file)
@@ -19,17 +19,10 @@ in {
     };
   };
 
-  imports = [
-    ../commons/stats.nix
-  ];
-
   config = lib.mkMerge [
     (lib.mkIf cfg.production.enable {
       secrets.keys = piedsjaloux_prod.keys;
-      services.myWebsites.commons.stats.enable = true;
-      services.myWebsites.commons.stats.sites = [
-        { name = "piedsjaloux.fr"; }
-      ];
+      services.webstats.sites = [ { name = "piedsjaloux.fr"; } ];
 
       security.acme.certs."piedsjaloux" = config.services.myCertificates.certConfig // {
         domain = "piedsjaloux.fr";