diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 0105cc3cdf2..16897797914 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -176,6 +176,7 @@
./services/hardware/udisks2.nix
./services/hardware/upower.nix
./services/hardware/thermald.nix
+ ./services/logging/awstats.nix
./services/logging/fluentd.nix
./services/logging/klogd.nix
./services/logging/logcheck.nix
diff --git a/nixos/modules/services/logging/awstats.nix b/nixos/modules/services/logging/awstats.nix
new file mode 100644
index 00000000000..8ab7e6acd98
--- /dev/null
+++ b/nixos/modules/services/logging/awstats.nix
@@ -0,0 +1,123 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+ cfg = config.services.awstats;
+ package = pkgs.awstats;
+in
+
+{
+ options.services.awstats = {
+ enable = mkOption {
+ type = types.bool;
+ default = cfg.service.enable;
+ description = ''
+ Enable the awstats program (but not service).
+ Currently only simple httpd (Apache) configs are supported,
+ and awstats plugins may not work correctly.
+ '';
+ };
+ vardir = mkOption {
+ type = types.path;
+ default = "/var/lib/awstats";
+ description = "The directory where variable awstats data will be stored.";
+ };
+
+ extraConfig = mkOption {
+ type = types.lines;
+ default = "";
+ description = "Extra configuration to be appendend to awstats.conf.";
+ };
+
+ updateAt = mkOption {
+ type = types.nullOr types.string;
+ default = null;
+ example = "hourly";
+ description = ''
+ Specification of the time at which awstats will get updated.
+ (in the format described by
+ systemd.time
+ 5)
+ '';
+ };
+
+ service = {
+ enable = mkOption {
+ type = types.bool;
+ default = false;
+ description = ''Enable the awstats web service. This switches on httpd.'';
+ };
+ urlPrefix = mkOption {
+ type = types.string;
+ default = "/awstats";
+ description = "The URL prefix under which the awstats service appears.";
+ };
+ };
+ };
+
+
+ config = mkIf cfg.enable {
+ environment.systemPackages = [ package.bin ];
+ /* TODO:
+ - heed config.services.httpd.logPerVirtualHost, etc.
+ - Can't AllowToUpdateStatsFromBrowser, as CGI scripts don't have permission
+ to read the logs, and our httpd config apparently doesn't an option for that.
+ */
+ environment.etc."awstats/awstats.conf".source = pkgs.runCommand "awstats.conf"
+ { preferLocalBuild = true; }
+ ( let
+ cfg-httpd = config.services.httpd;
+ logFormat =
+ if cfg-httpd.logFormat == "combined" then "1" else
+ if cfg-httpd.logFormat == "common" then "4" else
+ throw "awstats service doesn't support Apache log format `${cfg-httpd.logFormat}`";
+ in
+ ''
+ sed \
+ -e 's|^\(DirData\)=.*$|\1="${cfg.vardir}"|' \
+ -e 's|^\(DirIcons\)=.*$|\1="icons"|' \
+ -e 's|^\(CreateDirDataIfNotExists\)=.*$|\1=1|' \
+ -e 's|^\(SiteDomain\)=.*$|\1="${cfg-httpd.hostName}"|' \
+ -e 's|^\(LogFile\)=.*$|\1="${cfg-httpd.logDir}/access_log"|' \
+ -e 's|^\(LogFormat\)=.*$|\1=${logFormat}|' \
+ < '${package.out}/wwwroot/cgi-bin/awstats.model.conf' > "$out"
+ echo '${cfg.extraConfig}' >> "$out"
+ '');
+
+ # The httpd sub-service showing awstats.
+ services.httpd.enable = mkIf cfg.service.enable true;
+ services.httpd.extraSubservices = mkIf cfg.service.enable [ { function = { serverInfo, ... }: {
+ extraConfig =
+ ''
+ Alias ${cfg.service.urlPrefix}/classes "${package.out}/wwwroot/classes/"
+ Alias ${cfg.service.urlPrefix}/css "${package.out}/wwwroot/css/"
+ Alias ${cfg.service.urlPrefix}/icons "${package.out}/wwwroot/icon/"
+ ScriptAlias ${cfg.service.urlPrefix}/ "${package.out}/wwwroot/cgi-bin/"
+
+
+ Options None
+ AllowOverride None
+ Order allow,deny
+ Allow from all
+
+ '';
+ startupScript =
+ let
+ inherit (serverInfo.serverConfig) user group;
+ in pkgs.writeScript "awstats_startup.sh"
+ ''
+ mkdir -p '${cfg.vardir}'
+ chown '${user}:${group}' '${cfg.vardir}'
+ '';
+ };}];
+
+ systemd.services.awstats-update = mkIf (cfg.updateAt != null) {
+ description = "awstats log collector";
+ script = "exec '${package.bin}/bin/awstats' -update -config=awstats.conf";
+ startAt = cfg.updateAt;
+ };
+ };
+
+}
+
diff --git a/pkgs/tools/system/awstats/default.nix b/pkgs/tools/system/awstats/default.nix
new file mode 100644
index 00000000000..f4a14155d68
--- /dev/null
+++ b/pkgs/tools/system/awstats/default.nix
@@ -0,0 +1,58 @@
+{ stdenv, fetchurl, perlPackages, jdk }:
+
+perlPackages.buildPerlPackage rec {
+ name = "awstats-${version}";
+ version = "7.4";
+
+ src = fetchurl {
+ url = "mirror://sourceforge/awstats/${name}.tar.gz";
+ sha256 = "0mdbilsl8g9a84qgyws4pakhqr3mfhs5g5dqbgsn9gn285rzxas3";
+ };
+
+ postPatch = ''
+ substituteInPlace wwwroot/cgi-bin/awstats.pl \
+ --replace /usr/share/awstats/ "$out/wwwroot/cgi-bin/"
+ '';
+
+ outputs = [ "out" "bin" "doc" ];
+
+ buildInputs = with perlPackages; [ ]; # plugins will need some
+
+ preConfigure = ''
+ touch Makefile.PL
+ patchShebangs .
+ '';
+
+ # build our own JAR
+ preBuild = ''
+ (
+ cd wwwroot/classes/src
+ rm ../*.jar
+ PATH="${jdk}/bin" "$(type -P perl)" Makefile.pl
+ test -f ../*.jar
+ )
+ '';
+
+ doCheck = false;
+
+ installPhase = ''
+ mkdir "$out"
+ mv wwwroot "$out/wwwroot"
+ rm -r "$out/wwwroot/classes/src/"
+
+ mkdir -p "$bin/bin"
+ ln -s "$out/wwwroot/cgi-bin/awstats.pl" "$bin/bin/awstats"
+
+ mkdir -p "$doc/share/"
+ mv README.md docs/
+ mv docs "$doc/share/awstats"
+ '';
+
+ meta = with stdenv.lib; {
+ description = "Real-time logfile analyzer to get advanced statistics";
+ homepage = http://awstats.org;
+ license = licenses.gpl3Plus;
+ platforms = platforms.linux;
+ };
+}
+
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 155d3348f8b..50ef66a66bb 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -676,6 +676,8 @@ let
aws_mturk_clt = callPackage ../tools/misc/aws-mturk-clt { };
+ awstats = callPackage ../tools/system/awstats { };
+
axel = callPackage ../tools/networking/axel { };
azureus = callPackage ../tools/networking/p2p/azureus { };