1 { lib, pkgs, config, ... }:
4 cfg = config.services.webstats;
6 options.services.webstats = {
7 dataDir = lib.mkOption {
9 default = "/var/lib/${name}";
11 The directory where Goaccess stores its data.
14 sites = lib.mkOption {
15 type = lib.types.listOf (lib.types.submodule {
18 type = lib.types.nullOr lib.types.path;
21 use custom goaccess configuration file instead of the
28 Domain name. Corresponds to the Apache file name and the
29 folder name in which the state will be saved.
35 description = "Sites to generate stats";
39 config = lib.mkIf (builtins.length cfg.sites > 0) {
40 users.users.root.packages = [
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"
53 d = pkgs.writeScriptBin "stats-${domain}" ''
54 #!${pkgs.stdenv.shell}
58 trap "rm -f $TMPFILE" EXIT
60 mkdir -p ${cfg.dataDir}/${domain}
61 for i in /var/log/httpd/access-${domain}*.gz; do
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}
67 in "${d}/bin/stats-${domain}";
68 allStats = sites: pkgs.writeScript "stats" ''
69 #!${pkgs.stdenv.shell}
71 mkdir -p ${cfg.dataDir}
72 ${builtins.concatStringsSep "\n" (map (v: stats v.name v.conf) sites)}
76 "5 0 * * * root ${allStats cfg.sites}"