]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - nixops/modules/websites/commons/stats.nix
Make goaccess a template
[perso/Immae/Config/Nix.git] / nixops / modules / websites / commons / stats.nix
index 921cde28157e9e3b3ab4045674177afcc6f345c8..73595f1ff7e71838c5e0068ac68939cba239e04a 100644 (file)
@@ -8,7 +8,10 @@ in {
       sites = lib.mkOption {
         type = lib.types.listOf (lib.types.submodule {
           options = {
-            conf = lib.mkOption { type = lib.types.path; };
+            conf = lib.mkOption {
+              type = lib.types.nullOr lib.types.path;
+              default = null;
+            };
             name = lib.mkOption { type = lib.types.string; };
           };
         });
@@ -19,27 +22,19 @@ in {
   };
 
   config = lib.mkIf cfg.enable {
-    environment.systemPackages = [
+    users.users.root.packages = [
       pkgs.goaccess
     ];
 
-    nixpkgs.overlays = [ (self: super: rec {
-      goaccess = super.goaccess.overrideAttrs(old: rec {
-        name = "goaccess-${version}";
-        version = "1.3";
-        src = self.fetchurl {
-          url = "https://tar.goaccess.io/${name}.tar.gz";
-          sha256 = "16vv3pj7pbraq173wlxa89jjsd279004j4kgzlrsk1dz4if5qxwc";
-        };
-        configureFlags = old.configureFlags ++ [ "--enable-tcb=btree" ];
-        buildInputs = old.buildInputs ++ [ self.tokyocabinet self.bzip2 ];
-      });
-    }) ];
-
     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
@@ -52,7 +47,7 @@ in {
             for i in /var/log/httpd/access_log-${domain}*.gz; do
               zcat "$i" | sed -n "/\\[$date_regex/ p" >> $TMPFILE
             done
-            goaccess $TMPFILE --no-progress -o /var/lib/goaccess/${domain}/index.html -p ${conf}
+            ${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" ''