diff options
Diffstat (limited to 'modules/webapps/webstats/default.nix')
-rw-r--r-- | modules/webapps/webstats/default.nix | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/modules/webapps/webstats/default.nix b/modules/webapps/webstats/default.nix deleted file mode 100644 index e873af2..0000000 --- a/modules/webapps/webstats/default.nix +++ /dev/null | |||
@@ -1,80 +0,0 @@ | |||
1 | { lib, pkgs, config, ... }: | ||
2 | let | ||
3 | name = "goaccess"; | ||
4 | cfg = config.services.webstats; | ||
5 | in { | ||
6 | options.services.webstats = { | ||
7 | dataDir = lib.mkOption { | ||
8 | type = lib.types.path; | ||
9 | default = "/var/lib/${name}"; | ||
10 | description = '' | ||
11 | The directory where Goaccess stores its data. | ||
12 | ''; | ||
13 | }; | ||
14 | sites = lib.mkOption { | ||
15 | type = lib.types.listOf (lib.types.submodule { | ||
16 | options = { | ||
17 | conf = lib.mkOption { | ||
18 | type = lib.types.nullOr lib.types.path; | ||
19 | default = null; | ||
20 | description = '' | ||
21 | use custom goaccess configuration file instead of the | ||
22 | default one. | ||
23 | ''; | ||
24 | }; | ||
25 | name = lib.mkOption { | ||
26 | type = lib.types.str; | ||
27 | description = '' | ||
28 | Domain name. Corresponds to the Apache file name and the | ||
29 | folder name in which the state will be saved. | ||
30 | ''; | ||
31 | }; | ||
32 | }; | ||
33 | }); | ||
34 | default = []; | ||
35 | description = "Sites to generate stats"; | ||
36 | }; | ||
37 | }; | ||
38 | |||
39 | config = lib.mkIf (builtins.length cfg.sites > 0) { | ||
40 | users.users.root.packages = [ | ||
41 | pkgs.goaccess | ||
42 | ]; | ||
43 | |||
44 | services.cron = { | ||
45 | enable = true; | ||
46 | systemCronJobs = let | ||
47 | stats = domain: conf: let | ||
48 | config = if builtins.isNull conf | ||
49 | then pkgs.runCommand "goaccess.conf" { | ||
50 | dbPath = "${cfg.dataDir}/${domain}"; | ||
51 | } "substituteAll ${./goaccess.conf} $out" | ||
52 | else conf; | ||
53 | d = pkgs.writeScriptBin "stats-${domain}" '' | ||
54 | #!${pkgs.stdenv.shell} | ||
55 | set -e | ||
56 | shopt -s nullglob | ||
57 | TMPFILE=$(mktemp) | ||
58 | trap "rm -f $TMPFILE" EXIT | ||
59 | |||
60 | mkdir -p ${cfg.dataDir}/${domain} | ||
61 | for i in /var/log/httpd/access-${domain}*.gz; do | ||
62 | zcat "$i" >> $TMPFILE | ||
63 | done | ||
64 | cat /var/log/httpd/access-${domain}.log > $TMPFILE | ||
65 | ${pkgs.goaccess}/bin/goaccess $TMPFILE --no-progress -o ${cfg.dataDir}/${domain}/index.html -p ${config} | ||
66 | ''; | ||
67 | in "${d}/bin/stats-${domain}"; | ||
68 | allStats = sites: pkgs.writeScript "stats" '' | ||
69 | #!${pkgs.stdenv.shell} | ||
70 | |||
71 | mkdir -p ${cfg.dataDir} | ||
72 | ${builtins.concatStringsSep "\n" (map (v: stats v.name v.conf) sites)} | ||
73 | ''; | ||
74 | in | ||
75 | [ | ||
76 | "5 0 * * * root ${allStats cfg.sites}" | ||
77 | ]; | ||
78 | }; | ||
79 | }; | ||
80 | } | ||