X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FConfig%2FNix.git;a=blobdiff_plain;f=modules%2Fwebapps%2Fwebstats%2Fdefault.nix;fp=nixops%2Fmodules%2Fwebsites%2Fcommons%2Fstats.nix;h=f4916bd011fc03ceb61e4b037a586937cb00e5cb;hp=73595f1ff7e71838c5e0068ac68939cba239e04a;hb=9eae2b47b7b315b05a0e010f3003bd875685e260;hpb=b7ee93fcdee2509cd4c0caec2c5c59ccff5bab2c diff --git a/nixops/modules/websites/commons/stats.nix b/modules/webapps/webstats/default.nix similarity index 53% rename from nixops/modules/websites/commons/stats.nix rename to modules/webapps/webstats/default.nix index 73595f1..f4916bd 100644 --- a/nixops/modules/websites/commons/stats.nix +++ b/modules/webapps/webstats/default.nix @@ -1,27 +1,42 @@ { lib, pkgs, config, mylibs, ... }: let - cfg = config.services.myWebsites.commons.stats; + name = "goaccess"; + cfg = config.services.webstats; 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; }; + options.services.webstats = { + dataDir = lib.mkOption { + type = lib.types.path; + default = "/var/lib/${name}"; + description = '' + The directory where Goaccess stores its data. + ''; + }; + sites = lib.mkOption { + type = lib.types.listOf (lib.types.submodule { + options = { + conf = lib.mkOption { + type = lib.types.nullOr lib.types.path; + default = null; + description = '' + use custom goaccess configuration file instead of the + default one. + ''; + }; + name = lib.mkOption { + type = lib.types.string; + description = '' + Domain name. Corresponds to the Apache file name and the + folder name in which the state will be saved. + ''; }; - }); - default = []; - description = "Sites to generate stats"; - }; + }; + }); + default = []; + description = "Sites to generate stats"; }; }; - config = lib.mkIf cfg.enable { + config = lib.mkIf (builtins.length cfg.sites > 0) { users.users.root.packages = [ pkgs.goaccess ]; @@ -32,7 +47,7 @@ in { stats = domain: conf: let config = if builtins.isNull conf then pkgs.runCommand "goaccess.conf" { - dbPath = "/var/lib/goaccess/${domain}"; + dbPath = "${cfg.dataDir}/${domain}"; } "substituteAll ${./goaccess.conf} $out" else conf; d = pkgs.writeScriptBin "stats-${domain}" '' @@ -47,7 +62,7 @@ in { 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} + ${pkgs.goaccess}/bin/goaccess $TMPFILE --no-progress -o ${cfg.dataDir}/${domain}/index.html -p ${config} ''; in "${d}/bin/stats-${domain}"; allStats = sites: pkgs.writeScript "stats" '' @@ -64,6 +79,6 @@ in { system.activationScripts.goaccess = '' mkdir -p /var/lib/goaccess '' + - builtins.concatStringsSep "\n" (map (v: "mkdir -p /var/lib/goaccess/${v.name}") cfg.sites); + builtins.concatStringsSep "\n" (map (v: "mkdir -p ${cfg.dataDir}/${v.name}") cfg.sites); }; }