git.iko.soy/typeable/nixpkgs
on master help sign in
awstats: init at 7.4, including a simple service
commit6f9fe31b4237c877a840600f4fccc2d71e8c717c authorVladimír Čunát <vcunat@gmail.com> dateWed 9 Mar 2016, 19:50 (11 years ago) parent8500109
4 files changed+184
nixos/modules/module-list.nix+1 nixos/modules/services/logging/awstats.nix+123 pkgs/tools/system/awstats/default.nix+58 pkgs/top-level/all-packages.nix+2
nixos/modules/module-list.nix+1
@@ -176,6 +176,7 @@
176176 ./services/hardware/udisks2.nix
177177 ./services/hardware/upower.nix
178178 ./services/hardware/thermald.nix
179+ ./services/logging/awstats.nix
179180 ./services/logging/fluentd.nix
180181 ./services/logging/klogd.nix
181182 ./services/logging/logcheck.nix
nixos/modules/services/logging/awstats.nixnew file+123
@@ -0,0 +1,123 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.awstats;
7+ package = pkgs.awstats;
8+in
9+
10+{
11+ options.services.awstats = {
12+ enable = mkOption {
13+ type = types.bool;
14+ default = cfg.service.enable;
15+ description = ''
16+ Enable the awstats program (but not service).
17+ Currently only simple httpd (Apache) configs are supported,
18+ and awstats plugins may not work correctly.
19+ '';
20+ };
21+ vardir = mkOption {
22+ type = types.path;
23+ default = "/var/lib/awstats";
24+ description = "The directory where variable awstats data will be stored.";
25+ };
26+
27+ extraConfig = mkOption {
28+ type = types.lines;
29+ default = "";
30+ description = "Extra configuration to be appendend to awstats.conf.";
31+ };
32+
33+ updateAt = mkOption {
34+ type = types.nullOr types.string;
35+ default = null;
36+ example = "hourly";
37+ description = ''
38+ Specification of the time at which awstats will get updated.
39+ (in the format described by <citerefentry>
40+ <refentrytitle>systemd.time</refentrytitle>
41+ <manvolnum>5</manvolnum></citerefentry>)
42+ '';
43+ };
44+
45+ service = {
46+ enable = mkOption {
47+ type = types.bool;
48+ default = false;
49+ description = ''Enable the awstats web service. This switches on httpd.'';
50+ };
51+ urlPrefix = mkOption {
52+ type = types.string;
53+ default = "/awstats";
54+ description = "The URL prefix under which the awstats service appears.";
55+ };
56+ };
57+ };
58+
59+
60+ config = mkIf cfg.enable {
61+ environment.systemPackages = [ package.bin ];
62+ /* TODO:
63+ - heed config.services.httpd.logPerVirtualHost, etc.
64+ - Can't AllowToUpdateStatsFromBrowser, as CGI scripts don't have permission
65+ to read the logs, and our httpd config apparently doesn't an option for that.
66+ */
67+ environment.etc."awstats/awstats.conf".source = pkgs.runCommand "awstats.conf"
68+ { preferLocalBuild = true; }
69+ ( let
70+ cfg-httpd = config.services.httpd;
71+ logFormat =
72+ if cfg-httpd.logFormat == "combined" then "1" else
73+ if cfg-httpd.logFormat == "common" then "4" else
74+ throw "awstats service doesn't support Apache log format `${cfg-httpd.logFormat}`";
75+ in
76+ ''
77+ sed \
78+ -e 's|^\(DirData\)=.*$|\1="${cfg.vardir}"|' \
79+ -e 's|^\(DirIcons\)=.*$|\1="icons"|' \
80+ -e 's|^\(CreateDirDataIfNotExists\)=.*$|\1=1|' \
81+ -e 's|^\(SiteDomain\)=.*$|\1="${cfg-httpd.hostName}"|' \
82+ -e 's|^\(LogFile\)=.*$|\1="${cfg-httpd.logDir}/access_log"|' \
83+ -e 's|^\(LogFormat\)=.*$|\1=${logFormat}|' \
84+ < '${package.out}/wwwroot/cgi-bin/awstats.model.conf' > "$out"
85+ echo '${cfg.extraConfig}' >> "$out"
86+ '');
87+
88+ # The httpd sub-service showing awstats.
89+ services.httpd.enable = mkIf cfg.service.enable true;
90+ services.httpd.extraSubservices = mkIf cfg.service.enable [ { function = { serverInfo, ... }: {
91+ extraConfig =
92+ ''
93+ Alias ${cfg.service.urlPrefix}/classes "${package.out}/wwwroot/classes/"
94+ Alias ${cfg.service.urlPrefix}/css "${package.out}/wwwroot/css/"
95+ Alias ${cfg.service.urlPrefix}/icons "${package.out}/wwwroot/icon/"
96+ ScriptAlias ${cfg.service.urlPrefix}/ "${package.out}/wwwroot/cgi-bin/"
97+
98+ <Directory "${package.out}/wwwroot">
99+ Options None
100+ AllowOverride None
101+ Order allow,deny
102+ Allow from all
103+ </Directory>
104+ '';
105+ startupScript =
106+ let
107+ inherit (serverInfo.serverConfig) user group;
108+ in pkgs.writeScript "awstats_startup.sh"
109+ ''
110+ mkdir -p '${cfg.vardir}'
111+ chown '${user}:${group}' '${cfg.vardir}'
112+ '';
113+ };}];
114+
115+ systemd.services.awstats-update = mkIf (cfg.updateAt != null) {
116+ description = "awstats log collector";
117+ script = "exec '${package.bin}/bin/awstats' -update -config=awstats.conf";
118+ startAt = cfg.updateAt;
119+ };
120+ };
121+
122+}
123+
pkgs/tools/system/awstats/default.nixnew file+58
@@ -0,0 +1,58 @@
1+{ stdenv, fetchurl, perlPackages, jdk }:
2+
3+perlPackages.buildPerlPackage rec {
4+ name = "awstats-${version}";
5+ version = "7.4";
6+
7+ src = fetchurl {
8+ url = "mirror://sourceforge/awstats/${name}.tar.gz";
9+ sha256 = "0mdbilsl8g9a84qgyws4pakhqr3mfhs5g5dqbgsn9gn285rzxas3";
10+ };
11+
12+ postPatch = ''
13+ substituteInPlace wwwroot/cgi-bin/awstats.pl \
14+ --replace /usr/share/awstats/ "$out/wwwroot/cgi-bin/"
15+ '';
16+
17+ outputs = [ "out" "bin" "doc" ];
18+
19+ buildInputs = with perlPackages; [ ]; # plugins will need some
20+
21+ preConfigure = ''
22+ touch Makefile.PL
23+ patchShebangs .
24+ '';
25+
26+ # build our own JAR
27+ preBuild = ''
28+ (
29+ cd wwwroot/classes/src
30+ rm ../*.jar
31+ PATH="${jdk}/bin" "$(type -P perl)" Makefile.pl
32+ test -f ../*.jar
33+ )
34+ '';
35+
36+ doCheck = false;
37+
38+ installPhase = ''
39+ mkdir "$out"
40+ mv wwwroot "$out/wwwroot"
41+ rm -r "$out/wwwroot/classes/src/"
42+
43+ mkdir -p "$bin/bin"
44+ ln -s "$out/wwwroot/cgi-bin/awstats.pl" "$bin/bin/awstats"
45+
46+ mkdir -p "$doc/share/"
47+ mv README.md docs/
48+ mv docs "$doc/share/awstats"
49+ '';
50+
51+ meta = with stdenv.lib; {
52+ description = "Real-time logfile analyzer to get advanced statistics";
53+ homepage = http://awstats.org;
54+ license = licenses.gpl3Plus;
55+ platforms = platforms.linux;
56+ };
57+}
58+
pkgs/top-level/all-packages.nix+2
@@ -676,6 +676,8 @@ let
676676
677677 aws_mturk_clt = callPackage ../tools/misc/aws-mturk-clt { };
678678
679+ awstats = callPackage ../tools/system/awstats { };
680+
679681 axel = callPackage ../tools/networking/axel { };
680682
681683 azureus = callPackage ../tools/networking/p2p/azureus { };