···
Enable piwik web analytics with php-fpm backend.
27
+
Either the nginx option or the webServerUser option is mandatory.
webServerUser = mkOption {
32
+
type = types.nullOr types.str;
34
+
example = "lighttpd";
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.
If you want to use another webserver than nginx, you need to set this to that server's user
and pass fastcgi requests to `index.php` and `piwik.php` to this socket.
···
60
-
# TODO: for maximum flexibility, it would be nice to use nginx's vhost_options module
61
-
# but this only makes sense if we can somehow specify defaults suitable for piwik.
62
-
# But users can always copy the piwik nginx config to their configuration.nix and customize it.
63
-
type = types.nullOr (types.submodule {
65
-
virtualHost = mkOption {
67
-
default = "piwik.${config.networking.hostName}";
68
-
example = "piwik.$\{config.networking.hostName\}";
70
-
Name of the nginx virtualhost to use and set up.
73
-
enableSSL = mkOption {
76
-
description = "Whether to enable https.";
78
-
forceSSL = mkOption {
81
-
description = "Whether to always redirect to https.";
83
-
enableACME = mkOption {
86
-
description = "Whether to ask Let's Encrypt to sign a certificate for this vhost.";
63
+
type = types.nullOr (types.submodule (import ../web-servers/nginx/vhost-options.nix {
91
-
example = { virtualHost = "stats.$\{config.networking.hostName\}"; };
68
+
serverName = "stats.$\{config.networking.hostName\}";
93
-
The options to use to configure an nginx virtualHost.
94
-
If null (the default), no nginx virtualHost will be configured.
72
+
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.
74
+
Set this to {} to just enable the virtualHost if you don't need any customization.
75
+
If enabled, then by default, the serverName is piwik.$\{config.networking.hostName\}, SSL is active,
76
+
and certificates are acquired via ACME.
77
+
If this is set to null (the default), no nginx virtualHost will be configured.
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."
89
+
assertion = cfg.nginx != null || cfg.webServerUser != null;
90
+
message = "Either services.piwik.nginx or services.piwik.nginx.webServerUser is mandatory";
users.extraUsers.${user} = {
···
serviceConfig.UMask = "0007";
156
-
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 "";
159
-
listen.owner = ${cfg.webServerUser}
156
+
listen.owner = ${socketOwner}
···
# https://fralef.me/piwik-hardening-with-nginx-and-php-fpm.html
# https://github.com/perusio/piwik-nginx
173
-
${cfg.nginx.virtualHost} = {
174
-
root = "${pkgs.piwik}/share";
175
-
enableSSL = cfg.nginx.enableSSL;
176
-
enableACME = cfg.nginx.enableACME;
177
-
forceSSL = cfg.nginx.forceSSL;
170
+
"${user}.${config.networking.hostName}" = mkMerge [ cfg.nginx {
171
+
# don't allow to override root, as it will almost certainly break piwik
172
+
root = mkForce "${pkgs.piwik}/share";
174
+
# allow to override SSL settings if necessary, i.e. when using another method than ACME
175
+
# but enable them by default, as sensitive login and piwik data should not be transmitted in clear text.
176
+
forceSSL = mkDefault true;
177
+
enableACME = mkDefault true;
···
locations."= /piwik.js".extraConfig = ''