diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-01-10 22:40:32 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-01-10 22:40:32 +0100 |
commit | e4a945cd175fa78ee6373f2a30505c4322befa2b (patch) | |
tree | 8e958eaa618a06dd3fb588540ec5fc2794a25487 /virtual | |
parent | f8bde3d6d31da84b5e81bdfc4f96efdf6bec3df2 (diff) | |
download | Nix-e4a945cd175fa78ee6373f2a30505c4322befa2b.tar.gz Nix-e4a945cd175fa78ee6373f2a30505c4322befa2b.tar.zst Nix-e4a945cd175fa78ee6373f2a30505c4322befa2b.zip |
Move goaccess to specific module
Diffstat (limited to 'virtual')
-rw-r--r-- | virtual/eldiron.nix | 53 | ||||
-rw-r--r-- | virtual/modules/websites/aten.nix | 8 | ||||
-rw-r--r-- | virtual/modules/websites/chloe.nix | 8 | ||||
-rw-r--r-- | virtual/modules/websites/commons/stats.nix | 66 | ||||
-rw-r--r-- | virtual/modules/websites/connexionswing.nix | 8 | ||||
-rw-r--r-- | virtual/modules/websites/ludivine.nix | 8 | ||||
-rw-r--r-- | virtual/modules/websites/piedsjaloux.nix | 12 |
7 files changed, 110 insertions, 53 deletions
diff --git a/virtual/eldiron.nix b/virtual/eldiron.nix index a1e6909..e1edc01 100644 --- a/virtual/eldiron.nix +++ b/virtual/eldiron.nix | |||
@@ -36,19 +36,6 @@ | |||
36 | services.myWebsites.production.enable = true; | 36 | services.myWebsites.production.enable = true; |
37 | services.myWebsites.integration.enable = true; | 37 | services.myWebsites.integration.enable = true; |
38 | 38 | ||
39 | nixpkgs.config.packageOverrides = oldpkgs: rec { | ||
40 | goaccess = oldpkgs.goaccess.overrideAttrs(old: rec { | ||
41 | name = "goaccess-${version}"; | ||
42 | version = "1.3"; | ||
43 | src = pkgs.fetchurl { | ||
44 | url = "https://tar.goaccess.io/${name}.tar.gz"; | ||
45 | sha256 = "16vv3pj7pbraq173wlxa89jjsd279004j4kgzlrsk1dz4if5qxwc"; | ||
46 | }; | ||
47 | configureFlags = old.configureFlags ++ [ "--enable-tcb=btree" ]; | ||
48 | buildInputs = old.buildInputs ++ [ pkgs.tokyocabinet pkgs.bzip2 ]; | ||
49 | }); | ||
50 | }; | ||
51 | |||
52 | networking = { | 39 | networking = { |
53 | firewall = { | 40 | firewall = { |
54 | enable = true; | 41 | enable = true; |
@@ -96,7 +83,6 @@ | |||
96 | pkgs.telnet | 83 | pkgs.telnet |
97 | pkgs.htop | 84 | pkgs.htop |
98 | pkgs.vim | 85 | pkgs.vim |
99 | pkgs.goaccess | ||
100 | occ | 86 | occ |
101 | ]; | 87 | ]; |
102 | 88 | ||
@@ -152,15 +138,6 @@ | |||
152 | install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions/mantisbt | 138 | install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions/mantisbt |
153 | install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions/davical | 139 | install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions/davical |
154 | ''; | 140 | ''; |
155 | # FIXME: initial sync | ||
156 | goaccess = '' | ||
157 | mkdir -p /var/lib/goaccess | ||
158 | mkdir -p /var/lib/goaccess/aten.pro | ||
159 | mkdir -p /var/lib/goaccess/ludivinecassal.com | ||
160 | mkdir -p /var/lib/goaccess/piedsjaloux.fr | ||
161 | mkdir -p /var/lib/goaccess/osteopathe-cc.fr | ||
162 | mkdir -p /var/lib/goaccess/connexionswing.com | ||
163 | ''; | ||
164 | }; | 141 | }; |
165 | 142 | ||
166 | environment.etc."ssh/ldap_authorized_keys" = let | 143 | environment.etc."ssh/ldap_authorized_keys" = let |
@@ -331,36 +308,6 @@ | |||
331 | ]; | 308 | ]; |
332 | }; | 309 | }; |
333 | 310 | ||
334 | services.cron = { | ||
335 | enable = true; | ||
336 | systemCronJobs = let | ||
337 | stats = domain: conf: let | ||
338 | d = pkgs.writeScriptBin "stats-${domain}" '' | ||
339 | #!${pkgs.stdenv.shell} | ||
340 | set -e | ||
341 | shopt -s nullglob | ||
342 | date_regex=$(LC_ALL=C date -d yesterday +'%d\/%b\/%Y') | ||
343 | TMPFILE=$(mktemp) | ||
344 | trap "rm -f $TMPFILE" EXIT | ||
345 | |||
346 | cat /var/log/httpd/access_log-${domain} | sed -n "/\\[$date_regex/ p" > $TMPFILE | ||
347 | for i in /var/log/httpd/access_log-${domain}*.gz; do | ||
348 | zcat "$i" | sed -n "/\\[$date_regex/ p" >> $TMPFILE | ||
349 | done | ||
350 | goaccess $TMPFILE --no-progress -o /var/lib/goaccess/${domain}/index.html -p ${conf} | ||
351 | ''; | ||
352 | in "${d}/bin/stats-${domain}"; | ||
353 | # FIXME: running several goaccess simultaneously seems to be | ||
354 | # bugged? | ||
355 | in [ | ||
356 | "5 0 * * * root ${stats "aten.pro" ./packages/aten_goaccess.conf}" | ||
357 | "6 0 * * * root ${stats "ludivinecassal.com" ./packages/ludivinecassal_goaccess.conf}" | ||
358 | "7 0 * * * root ${stats "piedsjaloux.fr" ./packages/piedsjaloux_goaccess.conf}" | ||
359 | "8 0 * * * root ${stats "osteopathe-cc.fr" ./packages/chloe_goaccess.conf}" | ||
360 | "9 0 * * * root ${stats "connexionswing.com" ./packages/connexionswing_goaccess.conf}" | ||
361 | ]; | ||
362 | }; | ||
363 | |||
364 | systemd.services.tt-rss = { | 311 | systemd.services.tt-rss = { |
365 | description = "Tiny Tiny RSS feeds update daemon"; | 312 | description = "Tiny Tiny RSS feeds update daemon"; |
366 | serviceConfig = { | 313 | serviceConfig = { |
diff --git a/virtual/modules/websites/aten.nix b/virtual/modules/websites/aten.nix index 53db03a..4688db3 100644 --- a/virtual/modules/websites/aten.nix +++ b/virtual/modules/websites/aten.nix | |||
@@ -17,6 +17,14 @@ in { | |||
17 | 17 | ||
18 | config = lib.mkMerge [ | 18 | config = lib.mkMerge [ |
19 | (lib.mkIf cfg.production.enable { | 19 | (lib.mkIf cfg.production.enable { |
20 | services.myWebsites.commons.stats.enable = true; | ||
21 | services.myWebsites.commons.stats.sites = [ | ||
22 | { | ||
23 | name = "aten.pro"; | ||
24 | conf = ../../packages/aten_goaccess.conf; | ||
25 | } | ||
26 | ]; | ||
27 | |||
20 | security.acme.certs."aten" = config.services.myCertificates.certConfig // { | 28 | security.acme.certs."aten" = config.services.myCertificates.certConfig // { |
21 | domain = "aten.pro"; | 29 | domain = "aten.pro"; |
22 | extraDomains = { | 30 | extraDomains = { |
diff --git a/virtual/modules/websites/chloe.nix b/virtual/modules/websites/chloe.nix index 67e8e1f..3309dd2 100644 --- a/virtual/modules/websites/chloe.nix +++ b/virtual/modules/websites/chloe.nix | |||
@@ -17,6 +17,14 @@ in { | |||
17 | 17 | ||
18 | config = lib.mkMerge [ | 18 | config = lib.mkMerge [ |
19 | (lib.mkIf cfg.production.enable { | 19 | (lib.mkIf cfg.production.enable { |
20 | services.myWebsites.commons.stats.enable = true; | ||
21 | services.myWebsites.commons.stats.sites = [ | ||
22 | { | ||
23 | name = "osteopathe-cc.fr"; | ||
24 | conf = ../../packages/chloe_goaccess.conf; | ||
25 | } | ||
26 | ]; | ||
27 | |||
20 | security.acme.certs."chloe" = config.services.myCertificates.certConfig // { | 28 | security.acme.certs."chloe" = config.services.myCertificates.certConfig // { |
21 | domain = "osteopathe-cc.fr"; | 29 | domain = "osteopathe-cc.fr"; |
22 | extraDomains = { | 30 | extraDomains = { |
diff --git a/virtual/modules/websites/commons/stats.nix b/virtual/modules/websites/commons/stats.nix new file mode 100644 index 0000000..a7ade3b --- /dev/null +++ b/virtual/modules/websites/commons/stats.nix | |||
@@ -0,0 +1,66 @@ | |||
1 | { lib, pkgs, config, mylibs, ... }: | ||
2 | let | ||
3 | cfg = config.services.myWebsites.commons.stats; | ||
4 | in { | ||
5 | options = { | ||
6 | services.myWebsites.commons.stats = { | ||
7 | enable = lib.mkEnableOption "enable statistics"; | ||
8 | sites = lib.mkOption { | ||
9 | # FIXME: specify | ||
10 | type = lib.types.listOf (lib.types.unspecified); | ||
11 | default = []; | ||
12 | description = "Sites to generate stats"; | ||
13 | }; | ||
14 | }; | ||
15 | }; | ||
16 | |||
17 | config = lib.mkIf cfg.enable { | ||
18 | environment.systemPackages = [ | ||
19 | pkgs.goaccess | ||
20 | ]; | ||
21 | |||
22 | nixpkgs.config.packageOverrides = oldpkgs: rec { | ||
23 | goaccess = oldpkgs.goaccess.overrideAttrs(old: rec { | ||
24 | name = "goaccess-${version}"; | ||
25 | version = "1.3"; | ||
26 | src = pkgs.fetchurl { | ||
27 | url = "https://tar.goaccess.io/${name}.tar.gz"; | ||
28 | sha256 = "16vv3pj7pbraq173wlxa89jjsd279004j4kgzlrsk1dz4if5qxwc"; | ||
29 | }; | ||
30 | configureFlags = old.configureFlags ++ [ "--enable-tcb=btree" ]; | ||
31 | buildInputs = old.buildInputs ++ [ pkgs.tokyocabinet pkgs.bzip2 ]; | ||
32 | }); | ||
33 | }; | ||
34 | |||
35 | services.cron = { | ||
36 | enable = true; | ||
37 | systemCronJobs = let | ||
38 | stats = domain: conf: let | ||
39 | d = pkgs.writeScriptBin "stats-${domain}" '' | ||
40 | #!${pkgs.stdenv.shell} | ||
41 | set -e | ||
42 | shopt -s nullglob | ||
43 | date_regex=$(LC_ALL=C date -d yesterday +'%d\/%b\/%Y') | ||
44 | TMPFILE=$(mktemp) | ||
45 | trap "rm -f $TMPFILE" EXIT | ||
46 | |||
47 | cat /var/log/httpd/access_log-${domain} | sed -n "/\\[$date_regex/ p" > $TMPFILE | ||
48 | for i in /var/log/httpd/access_log-${domain}*.gz; do | ||
49 | zcat "$i" | sed -n "/\\[$date_regex/ p" >> $TMPFILE | ||
50 | done | ||
51 | goaccess $TMPFILE --no-progress -o /var/lib/goaccess/${domain}/index.html -p ${conf} | ||
52 | ''; | ||
53 | in "${d}/bin/stats-${domain}"; | ||
54 | # FIXME: running several goaccess simultaneously seems to be | ||
55 | # bugged? | ||
56 | in | ||
57 | pkgs.lib.lists.imap0 (i: v: "${toString (i+5)} 0 * * * root ${stats v.name v.conf}") cfg.sites; | ||
58 | }; | ||
59 | |||
60 | # FIXME: initial sync | ||
61 | system.activationScripts.goaccess = '' | ||
62 | mkdir -p /var/lib/goaccess | ||
63 | '' + | ||
64 | builtins.concatStringsSep "\n" (map (v: "mkdir -p /var/lib/goaccess/${v.name}") cfg.sites); | ||
65 | }; | ||
66 | } | ||
diff --git a/virtual/modules/websites/connexionswing.nix b/virtual/modules/websites/connexionswing.nix index dcc7264..9fc0cec 100644 --- a/virtual/modules/websites/connexionswing.nix +++ b/virtual/modules/websites/connexionswing.nix | |||
@@ -17,6 +17,14 @@ in { | |||
17 | 17 | ||
18 | config = lib.mkMerge [ | 18 | config = lib.mkMerge [ |
19 | (lib.mkIf cfg.production.enable { | 19 | (lib.mkIf cfg.production.enable { |
20 | services.myWebsites.commons.stats.enable = true; | ||
21 | services.myWebsites.commons.stats.sites = [ | ||
22 | { | ||
23 | name = "connexionswing.com"; | ||
24 | conf = ../../packages/connexionswing_goaccess.conf; | ||
25 | } | ||
26 | ]; | ||
27 | |||
20 | security.acme.certs."connexionswing" = config.services.myCertificates.certConfig // { | 28 | security.acme.certs."connexionswing" = config.services.myCertificates.certConfig // { |
21 | domain = "connexionswing.com"; | 29 | domain = "connexionswing.com"; |
22 | extraDomains = { | 30 | extraDomains = { |
diff --git a/virtual/modules/websites/ludivine.nix b/virtual/modules/websites/ludivine.nix index 6eb98e7..b3c1c51 100644 --- a/virtual/modules/websites/ludivine.nix +++ b/virtual/modules/websites/ludivine.nix | |||
@@ -17,6 +17,14 @@ in { | |||
17 | 17 | ||
18 | config = lib.mkMerge [ | 18 | config = lib.mkMerge [ |
19 | (lib.mkIf cfg.production.enable { | 19 | (lib.mkIf cfg.production.enable { |
20 | services.myWebsites.commons.stats.enable = true; | ||
21 | services.myWebsites.commons.stats.sites = [ | ||
22 | { | ||
23 | name = "ludivinecassal.com"; | ||
24 | conf = ../../packages/ludivinecassal_goaccess.conf; | ||
25 | } | ||
26 | ]; | ||
27 | |||
20 | security.acme.certs."ludivinecassal" = config.services.myCertificates.certConfig // { | 28 | security.acme.certs."ludivinecassal" = config.services.myCertificates.certConfig // { |
21 | domain = "ludivinecassal.com"; | 29 | domain = "ludivinecassal.com"; |
22 | extraDomains = { | 30 | extraDomains = { |
diff --git a/virtual/modules/websites/piedsjaloux.nix b/virtual/modules/websites/piedsjaloux.nix index 46161c7..451ae52 100644 --- a/virtual/modules/websites/piedsjaloux.nix +++ b/virtual/modules/websites/piedsjaloux.nix | |||
@@ -15,8 +15,20 @@ in { | |||
15 | }; | 15 | }; |
16 | }; | 16 | }; |
17 | 17 | ||
18 | imports = [ | ||
19 | ./commons/stats.nix | ||
20 | ]; | ||
21 | |||
18 | config = lib.mkMerge [ | 22 | config = lib.mkMerge [ |
19 | (lib.mkIf cfg.production.enable { | 23 | (lib.mkIf cfg.production.enable { |
24 | services.myWebsites.commons.stats.enable = true; | ||
25 | services.myWebsites.commons.stats.sites = [ | ||
26 | { | ||
27 | name = "piedsjaloux.fr"; | ||
28 | conf = ../../packages/piedsjaloux_goaccess.conf; | ||
29 | } | ||
30 | ]; | ||
31 | |||
20 | security.acme.certs."piedsjaloux" = config.services.myCertificates.certConfig // { | 32 | security.acme.certs."piedsjaloux" = config.services.myCertificates.certConfig // { |
21 | domain = "piedsjaloux.fr"; | 33 | domain = "piedsjaloux.fr"; |
22 | extraDomains = { | 34 | extraDomains = { |