aboutsummaryrefslogtreecommitdiff
path: root/nixops/modules/websites/commons/stats.nix
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2019-05-11 02:19:10 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2019-05-11 02:28:20 +0200
commitb7ee93fcdee2509cd4c0caec2c5c59ccff5bab2c (patch)
tree231d151cbf4f5d51e6ddac11a4355cacddc4b847 /nixops/modules/websites/commons/stats.nix
parentf826c67c0ff51c9724e8f54da6c9cbef78977858 (diff)
downloadNix-b7ee93fcdee2509cd4c0caec2c5c59ccff5bab2c.tar.gz
Nix-b7ee93fcdee2509cd4c0caec2c5c59ccff5bab2c.tar.zst
Nix-b7ee93fcdee2509cd4c0caec2c5c59ccff5bab2c.zip
Make goaccess a template
Diffstat (limited to 'nixops/modules/websites/commons/stats.nix')
-rw-r--r--nixops/modules/websites/commons/stats.nix12
1 files changed, 10 insertions, 2 deletions
diff --git a/nixops/modules/websites/commons/stats.nix b/nixops/modules/websites/commons/stats.nix
index 88559b1..73595f1 100644
--- a/nixops/modules/websites/commons/stats.nix
+++ b/nixops/modules/websites/commons/stats.nix
@@ -8,7 +8,10 @@ in {
8 sites = lib.mkOption { 8 sites = lib.mkOption {
9 type = lib.types.listOf (lib.types.submodule { 9 type = lib.types.listOf (lib.types.submodule {
10 options = { 10 options = {
11 conf = lib.mkOption { type = lib.types.path; }; 11 conf = lib.mkOption {
12 type = lib.types.nullOr lib.types.path;
13 default = null;
14 };
12 name = lib.mkOption { type = lib.types.string; }; 15 name = lib.mkOption { type = lib.types.string; };
13 }; 16 };
14 }); 17 });
@@ -27,6 +30,11 @@ in {
27 enable = true; 30 enable = true;
28 systemCronJobs = let 31 systemCronJobs = let
29 stats = domain: conf: let 32 stats = domain: conf: let
33 config = if builtins.isNull conf
34 then pkgs.runCommand "goaccess.conf" {
35 dbPath = "/var/lib/goaccess/${domain}";
36 } "substituteAll ${./goaccess.conf} $out"
37 else conf;
30 d = pkgs.writeScriptBin "stats-${domain}" '' 38 d = pkgs.writeScriptBin "stats-${domain}" ''
31 #!${pkgs.stdenv.shell} 39 #!${pkgs.stdenv.shell}
32 set -e 40 set -e
@@ -39,7 +47,7 @@ in {
39 for i in /var/log/httpd/access_log-${domain}*.gz; do 47 for i in /var/log/httpd/access_log-${domain}*.gz; do
40 zcat "$i" | sed -n "/\\[$date_regex/ p" >> $TMPFILE 48 zcat "$i" | sed -n "/\\[$date_regex/ p" >> $TMPFILE
41 done 49 done
42 ${pkgs.goaccess}/bin/goaccess $TMPFILE --no-progress -o /var/lib/goaccess/${domain}/index.html -p ${conf} 50 ${pkgs.goaccess}/bin/goaccess $TMPFILE --no-progress -o /var/lib/goaccess/${domain}/index.html -p ${config}
43 ''; 51 '';
44 in "${d}/bin/stats-${domain}"; 52 in "${d}/bin/stats-${domain}";
45 allStats = sites: pkgs.writeScript "stats" '' 53 allStats = sites: pkgs.writeScript "stats" ''