myids = ./myids.nix;
secrets = ./secrets.nix;
+ webstats = ./webapps/webstats;
diaspora = ./webapps/diaspora.nix;
etherpad-lite = ./webapps/etherpad-lite.nix;
mastodon = ./webapps/mastodon.nix;
{ 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
];
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}" ''
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" ''
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);
};
}
};
};
- imports = [
- ../commons/stats.nix
- ];
-
config = lib.mkMerge [
(lib.mkIf cfg.production.enable {
secrets.keys = aten_prod.keys;
- services.myWebsites.commons.stats.enable = true;
- services.myWebsites.commons.stats.sites = [
- { name = "aten.pro"; }
- ];
+ services.webstats.sites = [ { name = "aten.pro"; } ];
security.acme.certs."aten" = config.services.myCertificates.certConfig // {
domain = "aten.pro";
};
};
- imports = [
- ../commons/stats.nix
- ];
-
config = lib.mkMerge [
(lib.mkIf cfg.production.enable {
secrets.keys = chloe_prod.keys;
- services.myWebsites.commons.stats.enable = true;
- services.myWebsites.commons.stats.sites = [
- { name = "osteopathe-cc.fr"; }
- ];
+ services.webstats.sites = [ { name = "osteopathe-cc.fr"; } ];
security.acme.certs."chloe" = config.services.myCertificates.certConfig // {
domain = "osteopathe-cc.fr";
};
};
- imports = [
- ../commons/stats.nix
- ];
-
config = lib.mkMerge [
(lib.mkIf cfg.production.enable {
secrets.keys = connexionswing_prod.keys;
- services.myWebsites.commons.stats.enable = true;
- services.myWebsites.commons.stats.sites = [
- { name = "connexionswing.com"; }
- ];
+ services.webstats.sites = [ { name = "connexionswing.com"; } ];
security.acme.certs."connexionswing" = config.services.myCertificates.certConfig // {
domain = "connexionswing.com";
stats = {
extraConfig = ''
<Macro Stats %{domain}>
- Alias /awstats /var/lib/goaccess/%{domain}
- <Directory /var/lib/goaccess/%{domain}>
+ Alias /webstats ${config.services.webstats.dataDir}/%{domain}
+ <Directory ${config.services.webstats.dataDir}/%{domain}>
DirectoryIndex index.html
AllowOverride None
Require all granted
</Directory>
- <Location /awstats>
+ <Location /webstats>
Use LDAPConnect
Require ldap-group cn=%{domain},ou=stats,cn=httpd,ou=services,dc=immae,dc=eu
</Location>
};
};
- imports = [
- ../commons/stats.nix
- ];
-
config = lib.mkIf cfg.production.enable {
- services.myWebsites.commons.stats.enable = true;
- services.myWebsites.commons.stats.sites = [
- { name = "denisejerome.piedsjaloux.fr"; }
- ];
+ services.webstats.sites = [ { name = "denisejerome.piedsjaloux.fr"; } ];
security.acme.certs."denisejerome" = config.services.myCertificates.certConfig // {
domain = "denisejerome.piedsjaloux.fr";
};
};
- imports = [
- ../commons/stats.nix
- ];
-
config = lib.mkIf cfg.production.enable {
- services.myWebsites.commons.stats.enable = true;
- services.myWebsites.commons.stats.sites = [
- { name = "www.immae.eu"; }
- ];
+ services.webstats.sites = [ { name = "www.immae.eu"; } ];
security.acme.certs."eldiron".extraDomains."www.immae.eu" = null;
};
};
- imports = [
- ../commons/stats.nix
- ];
-
config = lib.mkIf cfg.production.enable {
- services.myWebsites.commons.stats.enable = true;
- services.myWebsites.commons.stats.sites = [
- { name = "naturaloutil.immae.eu"; }
- ];
+ services.webstats.sites = [ { name = "naturaloutil.immae.eu"; } ];
security.acme.certs."ftp".extraDomains."naturaloutil.immae.eu" = null;
security.acme.certs."naturaloutil" = config.services.myCertificates.certConfig // {
};
};
- imports = [
- ../commons/stats.nix
- ];
-
config = (lib.mkIf cfg.production.enable {
security.acme.certs."leila" = config.services.myCertificates.certConfig // {
domain = "leila.bouya.org";
php_admin_value[open_basedir] = "${varDir}:/tmp"
'';
- services.myWebsites.commons.stats.enable = true;
- services.myWebsites.commons.stats.sites = [
+ services.webstats.sites = [
{ name = "leila.bouya.org"; }
{ name = "chorale.leila.bouya.org"; }
];
};
};
- imports = [
- ../commons/stats.nix
- ];
-
config = lib.mkIf cfg.production.enable {
- services.myWebsites.commons.stats.enable = true;
- services.myWebsites.commons.stats.sites = [
- { name = "nassime.bouya.org"; }
- ];
+ services.webstats.sites = [ { name = "nassime.bouya.org"; } ];
security.acme.certs."ftp".extraDomains."nassime.bouya.org" = null;
security.acme.certs."nassime" = config.services.myCertificates.certConfig // {
};
};
- imports = [
- ../commons/stats.nix
- ];
-
config = lib.mkIf cfg.production.enable {
- services.myWebsites.commons.stats.enable = true;
- services.myWebsites.commons.stats.sites = [
- { name = "release.immae.eu"; }
- ];
+ services.webstats.sites = [ { name = "release.immae.eu"; } ];
security.acme.certs."eldiron".extraDomains."release.immae.eu" = null;
config = lib.mkMerge [
(lib.mkIf cfg.production.enable {
secrets.keys = ludivinecassal_prod.keys;
- services.myWebsites.commons.stats.enable = true;
- services.myWebsites.commons.stats.sites = [
- { name = "ludivinecassal.com"; }
- ];
+ services.webstats.sites = [ { name = "ludivinecassal.com"; } ];
security.acme.certs."ludivinecassal" = config.services.myCertificates.certConfig // {
domain = "ludivinecassal.com";
};
};
- imports = [
- ../commons/stats.nix
- ];
-
config = lib.mkMerge [
(lib.mkIf cfg.production.enable {
secrets.keys = piedsjaloux_prod.keys;
- services.myWebsites.commons.stats.enable = true;
- services.myWebsites.commons.stats.sites = [
- { name = "piedsjaloux.fr"; }
- ];
+ services.webstats.sites = [ { name = "piedsjaloux.fr"; } ];
security.acme.certs."piedsjaloux" = config.services.myCertificates.certConfig // {
domain = "piedsjaloux.fr";