@@ -24,14 +24,17 @@ in {
2424 default = false;
2525 description = ''
2626 Enable piwik web analytics with php-fpm backend.
27+ Either the nginx option or the webServerUser option is mandatory.
2728 '';
2829 };
2930
3031 webServerUser = mkOption {
31− type = types.str;
32− example = "nginx";
32+ type = types.nullOr types.str;
33+ default = null;
34+ example = "lighttpd";
3335 description = ''
34− Name of the owner of the ${phpSocket} fastcgi socket for piwik.
36+ Name of the web server user that forwards requests to the ${phpSocket} fastcgi socket for piwik if the nginx
37+ option is not used. Either this option or the nginx option is mandatory.
3538 If you want to use another webserver than nginx, you need to set this to that server's user
3639 and pass fastcgi requests to `index.php` and `piwik.php` to this socket.
3740 '';
@@ -67,6 +70,7 @@ in {
6770 };
6871 description = ''
6972 With this option, you can customize an nginx virtualHost which already has sensible defaults for piwik.
73+ Either this option or the webServerUser option is mandatory.
7074 Set this to {} to just enable the virtualHost if you don't need any customization.
7175 If enabled, then by default, the serverName is piwik.$\{config.networking.hostName\}, SSL is active,
7276 and certificates are acquired via ACME.
@@ -77,6 +81,14 @@ in {
7781 };
7882
7983 config = mkIf cfg.enable {
84+ warnings = mkIf (cfg.nginx != null && cfg.webServerUser != null) [
85+ "If services.piwik.nginx is set, services.piwik.nginx.webServerUser is ignored and should be removed."
86+ ];
87+
88+ assertions = [ {
89+ assertion = cfg.nginx != null || cfg.webServerUser != null;
90+ message = "Either services.piwik.nginx or services.piwik.nginx.webServerUser is mandatory";
91+ }];
8092
8193 users.extraUsers.${user} = {
8294 isSystemUser = true;
@@ -132,10 +144,16 @@ in {
132144 serviceConfig.UMask = "0007";
133145 };
134146
135− services.phpfpm.poolConfigs = {
147+ services.phpfpm.poolConfigs = let
148+ # workaround for when both are null and need to generate a string,
149+ # which is illegal, but as assertions apparently are being triggered *after* config generation,
150+ # we have to avoid already throwing errors at this previous stage.
151+ socketOwner = if (cfg.nginx != null) then config.services.nginx.user
152+ else if (cfg.webServerUser != null) then cfg.webServerUser else "";
153+ in {
136154 ${pool} = ''
137155 listen = "${phpSocket}"
138− listen.owner = ${cfg.webServerUser}
156+ listen.owner = ${socketOwner}
139157 listen.group = root
140158 listen.mode = 0600
141159 user = ${user}