]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - nixops/modules/websites/commons/stats.nix
Move webstats outside of nixops
[perso/Immae/Config/Nix.git] / nixops / modules / websites / commons / stats.nix
diff --git a/nixops/modules/websites/commons/stats.nix b/nixops/modules/websites/commons/stats.nix
deleted file mode 100644 (file)
index 73595f1..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-{ lib, pkgs, config, mylibs, ... }:
-let
-    cfg = config.services.myWebsites.commons.stats;
-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; };
-          };
-        });
-        default = [];
-        description = "Sites to generate stats";
-      };
-    };
-  };
-
-  config = lib.mkIf cfg.enable {
-    users.users.root.packages = [
-      pkgs.goaccess
-    ];
-
-    services.cron = {
-      enable = true;
-      systemCronJobs = let
-        stats = domain: conf: let
-          config = if builtins.isNull conf
-            then pkgs.runCommand "goaccess.conf" {
-                dbPath = "/var/lib/goaccess/${domain}";
-              } "substituteAll ${./goaccess.conf} $out"
-            else conf;
-          d = pkgs.writeScriptBin "stats-${domain}" ''
-            #!${pkgs.stdenv.shell}
-            set -e
-            shopt -s nullglob
-            date_regex=$(LC_ALL=C date -d yesterday +'%d\/%b\/%Y')
-            TMPFILE=$(mktemp)
-            trap "rm -f $TMPFILE" EXIT
-
-            cat /var/log/httpd/access_log-${domain} | sed -n "/\\[$date_regex/ p" > $TMPFILE
-            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}
-            '';
-          in "${d}/bin/stats-${domain}";
-        allStats = sites: pkgs.writeScript "stats" ''
-          #!${pkgs.stdenv.shell}
-
-          ${builtins.concatStringsSep "\n" (map (v: stats v.name v.conf) sites)}
-          '';
-      in
-        [
-          "5 0 * * * root ${allStats cfg.sites}"
-        ];
-    };
-
-    system.activationScripts.goaccess = ''
-      mkdir -p /var/lib/goaccess
-    '' +
-    builtins.concatStringsSep "\n" (map (v: "mkdir -p /var/lib/goaccess/${v.name}") cfg.sites);
-  };
-}