···7979 You can safely ignore this, unless you need a plugin that needs JavaScript tracker access.
8080 </para>
8181 </listitem>
8282-8383- <listitem>
8484- <para>
8585- Sending mail from piwik, e.g. for the password reset function, might not work out of the box:
8686- There's a problem with using <command>sendmail</command> from <literal>php-fpm</literal> that is
8787- being investigated at <link xlink:href="https://github.com/NixOS/nixpkgs/issues/26611" />.
8888- If you have (or don't have) this problem as well, please report it. You can enable SMTP as method
8989- to send mail in piwik's <quote>General Settings</quote> > <quote>Mail Server Settings</quote> instead.
9090- </para>
9191- </listitem>
9282 </itemizedlist>
9383 </section>
9484
+44-44
nixos/modules/services/web-apps/piwik.nix
···2424 default = false;
2525 description = ''
2626 Enable piwik web analytics with php-fpm backend.
2727+ Either the nginx option or the webServerUser option is mandatory.
2728 '';
2829 };
29303031 webServerUser = mkOption {
3131- type = types.str;
3232- example = "nginx";
3232+ type = types.nullOr types.str;
3333+ default = null;
3434+ example = "lighttpd";
3335 description = ''
3434- Name of the owner of the ${phpSocket} fastcgi socket for piwik.
3636+ Name of the web server user that forwards requests to the ${phpSocket} fastcgi socket for piwik if the nginx
3737+ 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 '';
···5760 };
58615962 nginx = mkOption {
6060- # TODO: for maximum flexibility, it would be nice to use nginx's vhost_options module
6161- # but this only makes sense if we can somehow specify defaults suitable for piwik.
6262- # But users can always copy the piwik nginx config to their configuration.nix and customize it.
6363- type = types.nullOr (types.submodule {
6464- options = {
6565- virtualHost = mkOption {
6666- type = types.str;
6767- default = "piwik.${config.networking.hostName}";
6868- example = "piwik.$\{config.networking.hostName\}";
6969- description = ''
7070- Name of the nginx virtualhost to use and set up.
7171- '';
7272- };
7373- enableSSL = mkOption {
7474- type = types.bool;
7575- default = true;
7676- description = "Whether to enable https.";
7777- };
7878- forceSSL = mkOption {
7979- type = types.bool;
8080- default = true;
8181- description = "Whether to always redirect to https.";
8282- };
8383- enableACME = mkOption {
8484- type = types.bool;
8585- default = true;
8686- description = "Whether to ask Let's Encrypt to sign a certificate for this vhost.";
8787- };
8888- };
8989- });
6363+ type = types.nullOr (types.submodule (import ../web-servers/nginx/vhost-options.nix {
6464+ inherit config lib;
6565+ }));
9066 default = null;
9191- example = { virtualHost = "stats.$\{config.networking.hostName\}"; };
6767+ example = {
6868+ serverName = "stats.$\{config.networking.hostName\}";
6969+ enableACME = false;
7070+ };
9271 description = ''
9393- The options to use to configure an nginx virtualHost.
9494- If null (the default), no nginx virtualHost will be configured.
7272+ With this option, you can customize an nginx virtualHost which already has sensible defaults for piwik.
7373+ Either this option or the webServerUser option is mandatory.
7474+ Set this to {} to just enable the virtualHost if you don't need any customization.
7575+ If enabled, then by default, the serverName is piwik.$\{config.networking.hostName\}, SSL is active,
7676+ and certificates are acquired via ACME.
7777+ If this is set to null (the default), no nginx virtualHost will be configured.
9578 '';
9679 };
9780 };
9881 };
998210083 config = mkIf cfg.enable {
8484+ warnings = mkIf (cfg.nginx != null && cfg.webServerUser != null) [
8585+ "If services.piwik.nginx is set, services.piwik.nginx.webServerUser is ignored and should be removed."
8686+ ];
8787+8888+ assertions = [ {
8989+ assertion = cfg.nginx != null || cfg.webServerUser != null;
9090+ message = "Either services.piwik.nginx or services.piwik.nginx.webServerUser is mandatory";
9191+ }];
1019210293 users.extraUsers.${user} = {
10394 isSystemUser = true;
···153144 serviceConfig.UMask = "0007";
154145 };
155146156156- services.phpfpm.poolConfigs = {
147147+ services.phpfpm.poolConfigs = let
148148+ # workaround for when both are null and need to generate a string,
149149+ # which is illegal, but as assertions apparently are being triggered *after* config generation,
150150+ # we have to avoid already throwing errors at this previous stage.
151151+ socketOwner = if (cfg.nginx != null) then config.services.nginx.user
152152+ else if (cfg.webServerUser != null) then cfg.webServerUser else "";
153153+ in {
157154 ${pool} = ''
158155 listen = "${phpSocket}"
159159- listen.owner = ${cfg.webServerUser}
156156+ listen.owner = ${socketOwner}
160157 listen.group = root
161158 listen.mode = 0600
162159 user = ${user}
···170167 # References:
171168 # https://fralef.me/piwik-hardening-with-nginx-and-php-fpm.html
172169 # https://github.com/perusio/piwik-nginx
173173- ${cfg.nginx.virtualHost} = {
174174- root = "${pkgs.piwik}/share";
175175- enableSSL = cfg.nginx.enableSSL;
176176- enableACME = cfg.nginx.enableACME;
177177- forceSSL = cfg.nginx.forceSSL;
170170+ "${user}.${config.networking.hostName}" = mkMerge [ cfg.nginx {
171171+ # don't allow to override root, as it will almost certainly break piwik
172172+ root = mkForce "${pkgs.piwik}/share";
173173+174174+ # allow to override SSL settings if necessary, i.e. when using another method than ACME
175175+ # but enable them by default, as sensitive login and piwik data should not be transmitted in clear text.
176176+ forceSSL = mkDefault true;
177177+ enableACME = mkDefault true;
178178179179 locations."/" = {
180180 index = "index.php";
···208208 locations."= /piwik.js".extraConfig = ''
209209 expires 1M;
210210 '';
211211- };
211211+ }];
212212 };
213213 };
214214