nixos/awstats: replace usage of deprecated services.httpd.extraSubservices

This commit is contained in:
Aaron Andersen 2019-08-11 08:57:48 -04:00
parent 31a577c736
commit ac4327c025

View File

@ -4,6 +4,7 @@ with lib;
let let
cfg = config.services.awstats; cfg = config.services.awstats;
httpd = config.services.httpd;
package = pkgs.awstats; package = pkgs.awstats;
in in
@ -67,50 +68,43 @@ in
environment.etc."awstats/awstats.conf".source = pkgs.runCommand "awstats.conf" environment.etc."awstats/awstats.conf".source = pkgs.runCommand "awstats.conf"
{ preferLocalBuild = true; } { preferLocalBuild = true; }
( let ( let
cfg-httpd = config.services.httpd;
logFormat = logFormat =
if cfg-httpd.logFormat == "combined" then "1" else if httpd.logFormat == "combined" then "1" else
if cfg-httpd.logFormat == "common" then "4" else if httpd.logFormat == "common" then "4" else
throw "awstats service doesn't support Apache log format `${cfg-httpd.logFormat}`"; throw "awstats service doesn't support Apache log format `${httpd.logFormat}`";
in in
'' ''
sed \ sed \
-e 's|^\(DirData\)=.*$|\1="${cfg.vardir}"|' \ -e 's|^\(DirData\)=.*$|\1="${cfg.vardir}"|' \
-e 's|^\(DirIcons\)=.*$|\1="icons"|' \ -e 's|^\(DirIcons\)=.*$|\1="icons"|' \
-e 's|^\(CreateDirDataIfNotExists\)=.*$|\1=1|' \ -e 's|^\(CreateDirDataIfNotExists\)=.*$|\1=1|' \
-e 's|^\(SiteDomain\)=.*$|\1="${cfg-httpd.hostName}"|' \ -e 's|^\(SiteDomain\)=.*$|\1="${httpd.hostName}"|' \
-e 's|^\(LogFile\)=.*$|\1="${cfg-httpd.logDir}/access_log"|' \ -e 's|^\(LogFile\)=.*$|\1="${httpd.logDir}/access_log"|' \
-e 's|^\(LogFormat\)=.*$|\1=${logFormat}|' \ -e 's|^\(LogFormat\)=.*$|\1=${logFormat}|' \
< '${package.out}/wwwroot/cgi-bin/awstats.model.conf' > "$out" < '${package.out}/wwwroot/cgi-bin/awstats.model.conf' > "$out"
echo '${cfg.extraConfig}' >> "$out" echo '${cfg.extraConfig}' >> "$out"
''); '');
# The httpd sub-service showing awstats. systemd.tmpfiles.rules = optionals cfg.service.enable [
services.httpd.enable = mkIf cfg.service.enable true; "d '${cfg.vardir}' - ${httpd.user} ${httpd.group} - -"
services.httpd.extraSubservices = mkIf cfg.service.enable [ { function = { serverInfo, ... }: { "Z '${cfg.vardir}' - ${httpd.user} ${httpd.group} - -"
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/"
<Directory "${package.out}/wwwroot"> # The httpd sub-service showing awstats.
Options None services.httpd = optionalAttrs cfg.service.enable {
AllowOverride None enable = true;
Order allow,deny extraConfig = ''
Allow from all Alias ${cfg.service.urlPrefix}/classes "${package.out}/wwwroot/classes/"
</Directory> Alias ${cfg.service.urlPrefix}/css "${package.out}/wwwroot/css/"
''; Alias ${cfg.service.urlPrefix}/icons "${package.out}/wwwroot/icon/"
startupScript = ScriptAlias ${cfg.service.urlPrefix}/ "${package.out}/wwwroot/cgi-bin/"
let
inherit (serverInfo.serverConfig) user group; <Directory "${package.out}/wwwroot">
in pkgs.writeScript "awstats_startup.sh" Options None
'' Require all granted
mkdir -p '${cfg.vardir}' </Directory>
chown '${user}:${group}' '${cfg.vardir}' '';
''; };
};}];
systemd.services.awstats-update = mkIf (cfg.updateAt != null) { systemd.services.awstats-update = mkIf (cfg.updateAt != null) {
description = "awstats log collector"; description = "awstats log collector";