···239239 <link xlink:href="http://borgbackup.readthedocs.io/en/stable/usage/upgrade.html#attic-and-borg-0-xx-to-borg-1-x">here</link>.
240240 </para>
241241 </listitem>
242242+ <listitem>
243243+ <para>
244244+ The Piwik analytics software was renamed to Matomo:
245245+ <itemizedlist>
246246+ <listitem>
247247+ <para>The package <literal>pkgs.piwik</literal> was renamed to <literal>pkgs.matomo</literal>.</para>
248248+ </listitem>
249249+ <listitem>
250250+ <para>The service <literal>services.piwik</literal> was renamed to <literal>services.matomo</literal>.</para>
251251+ </listitem>
252252+ <listitem>
253253+ <para>
254254+ The data directory <filename>/var/lib/piwik</filename> was renamed to <filename>/var/lib/matomo</filename>.
255255+ All files will be moved automatically on first startup, but you might need to adjust your backup scripts.
256256+ </para>
257257+ </listitem>
258258+ <listitem>
259259+ <para>
260260+ The <literal>piwik</literal> user was renamed to <literal>matomo</literal>.
261261+ The service will adjust ownership automatically for files in the data directory.
262262+ If you use unix socket authentication, remember to give the new <literal>matomo</literal> user
263263+ access to the database and to change the <literal>username</literal> to <literal>matomo</literal>
264264+ in the <literal>[database]</literal> section of <filename>/var/lib/matomo/config/config.ini.php</filename>.
265265+ </para>
266266+ </listitem>
267267+ <listitem>
268268+ <para>
269269+ If you named your database `piwik`, you might want to rename it to `matomo` to keep things clean,
270270+ but this is neither enforced nor required.
271271+ </para>
272272+ </listitem>
273273+ </itemizedlist>
274274+ </para>
275275+ </listitem>
242276</itemizedlist>
243277244278</section>
···11+<chapter xmlns="http://docbook.org/ns/docbook"
22+ xmlns:xlink="http://www.w3.org/1999/xlink"
33+ xmlns:xi="http://www.w3.org/2001/XInclude"
44+ version="5.0"
55+ xml:id="module-services-matomo">
66+77+ <title>Matomo</title>
88+ <para>
99+ Matomo is a real-time web analytics application.
1010+ This module configures php-fpm as backend for Matomo, optionally configuring an nginx vhost as well.
1111+ </para>
1212+1313+ <para>
1414+ An automatic setup is not suported by Matomo, so you need to configure Matomo itself in the browser-based Matomo setup.
1515+ </para>
1616+1717+1818+ <section>
1919+ <title>Database Setup</title>
2020+2121+ <para>
2222+ You also need to configure a MariaDB or MySQL database and -user for Matomo yourself,
2323+ and enter those credentials in your browser.
2424+ You can use passwordless database authentication via the UNIX_SOCKET authentication plugin
2525+ with the following SQL commands:
2626+2727+ <programlisting>
2828+ # For MariaDB
2929+ INSTALL PLUGIN unix_socket SONAME 'auth_socket';
3030+ CREATE DATABASE matomo;
3131+ CREATE USER 'matomo'@'localhost' IDENTIFIED WITH unix_socket;
3232+ GRANT ALL PRIVILEGES ON matomo.* TO 'matomo'@'localhost';
3333+3434+ # For MySQL
3535+ INSTALL PLUGIN auth_socket SONAME 'auth_socket.so';
3636+ CREATE DATABASE matomo;
3737+ CREATE USER 'matomo'@'localhost' IDENTIFIED WITH auth_socket;
3838+ GRANT ALL PRIVILEGES ON matomo.* TO 'matomo'@'localhost';
3939+ </programlisting>
4040+4141+ Then fill in <literal>matomo</literal> as database user and database name, and leave the password field blank.
4242+ This authentication works by allowing only the <literal>matomo</literal> unix user to authenticate as the
4343+ <literal>matomo</literal> database user (without needing a password), but no other users.
4444+ For more information on passwordless login, see
4545+ <link xlink:href="https://mariadb.com/kb/en/mariadb/unix_socket-authentication-plugin/" />.
4646+ </para>
4747+4848+ <para>
4949+ Of course, you can use password based authentication as well, e.g. when the database is not on the same host.
5050+ </para>
5151+ </section>
5252+5353+5454+ <section>
5555+ <title>Backup</title>
5656+ <para>
5757+ You only need to take backups of your MySQL database and the
5858+ <filename>/var/lib/matomo/config/config.ini.php</filename> file.
5959+ Use a user in the <literal>matomo</literal> group or root to access the file.
6060+ For more information, see <link xlink:href="https://matomo.org/faq/how-to-install/faq_138/" />.
6161+ </para>
6262+ </section>
6363+6464+6565+ <section>
6666+ <title>Issues</title>
6767+ <itemizedlist>
6868+ <listitem>
6969+ <para>
7070+ Matomo's file integrity check will warn you.
7171+ This is due to the patches necessary for NixOS, you can safely ignore this.
7272+ </para>
7373+ </listitem>
7474+7575+ <listitem>
7676+ <para>
7777+ Matomo will warn you that the JavaScript tracker is not writable.
7878+ This is because it's located in the read-only nix store.
7979+ You can safely ignore this, unless you need a plugin that needs JavaScript tracker access.
8080+ </para>
8181+ </listitem>
8282+ </itemizedlist>
8383+ </section>
8484+8585+8686+ <section>
8787+ <title>Using other Web Servers than nginx</title>
8888+8989+ <para>
9090+ You can use other web servers by forwarding calls for <filename>index.php</filename> and
9191+ <filename>piwik.php</filename> to the <literal>/run/phpfpm-matomo.sock</literal> fastcgi unix socket.
9292+ You can use the nginx configuration in the module code as a reference to what else should be configured.
9393+ </para>
9494+ </section>
9595+</chapter>
-95
nixos/modules/services/web-apps/piwik-doc.xml
···11-<chapter xmlns="http://docbook.org/ns/docbook"
22- xmlns:xlink="http://www.w3.org/1999/xlink"
33- xmlns:xi="http://www.w3.org/2001/XInclude"
44- version="5.0"
55- xml:id="module-services-piwik">
66-77- <title>Piwik</title>
88- <para>
99- Piwik is a real-time web analytics application.
1010- This module configures php-fpm as backend for piwik, optionally configuring an nginx vhost as well.
1111- </para>
1212-1313- <para>
1414- An automatic setup is not suported by piwik, so you need to configure piwik itself in the browser-based piwik setup.
1515- </para>
1616-1717-1818- <section>
1919- <title>Database Setup</title>
2020-2121- <para>
2222- You also need to configure a MariaDB or MySQL database and -user for piwik yourself,
2323- and enter those credentials in your browser.
2424- You can use passwordless database authentication via the UNIX_SOCKET authentication plugin
2525- with the following SQL commands:
2626-2727- <programlisting>
2828- # For MariaDB
2929- INSTALL PLUGIN unix_socket SONAME 'auth_socket';
3030- CREATE DATABASE piwik;
3131- CREATE USER 'piwik'@'localhost' IDENTIFIED WITH unix_socket;
3232- GRANT ALL PRIVILEGES ON piwik.* TO 'piwik'@'localhost';
3333-3434- # For MySQL
3535- INSTALL PLUGIN auth_socket SONAME 'auth_socket.so';
3636- CREATE DATABASE piwik;
3737- CREATE USER 'piwik'@'localhost' IDENTIFIED WITH auth_socket;
3838- GRANT ALL PRIVILEGES ON piwik.* TO 'piwik'@'localhost';
3939- </programlisting>
4040-4141- Then fill in <literal>piwik</literal> as database user and database name, and leave the password field blank.
4242- This authentication works by allowing only the <literal>piwik</literal> unix user to authenticate as the
4343- <literal>piwik</literal> database user (without needing a password), but no other users.
4444- For more information on passwordless login, see
4545- <link xlink:href="https://mariadb.com/kb/en/mariadb/unix_socket-authentication-plugin/" />.
4646- </para>
4747-4848- <para>
4949- Of course, you can use password based authentication as well, e.g. when the database is not on the same host.
5050- </para>
5151- </section>
5252-5353-5454- <section>
5555- <title>Backup</title>
5656- <para>
5757- You only need to take backups of your MySQL database and the
5858- <filename>/var/lib/piwik/config/config.ini.php</filename> file.
5959- Use a user in the <literal>piwik</literal> group or root to access the file.
6060- For more information, see <link xlink:href="https://piwik.org/faq/how-to-install/faq_138/" />.
6161- </para>
6262- </section>
6363-6464-6565- <section>
6666- <title>Issues</title>
6767- <itemizedlist>
6868- <listitem>
6969- <para>
7070- Piwik's file integrity check will warn you.
7171- This is due to the patches necessary for NixOS, you can safely ignore this.
7272- </para>
7373- </listitem>
7474-7575- <listitem>
7676- <para>
7777- Piwik will warn you that the JavaScript tracker is not writable.
7878- This is because it's located in the read-only nix store.
7979- You can safely ignore this, unless you need a plugin that needs JavaScript tracker access.
8080- </para>
8181- </listitem>
8282- </itemizedlist>
8383- </section>
8484-8585-8686- <section>
8787- <title>Using other Web Servers than nginx</title>
8888-8989- <para>
9090- You can use other web servers by forwarding calls for <filename>index.php</filename> and
9191- <filename>piwik.php</filename> to the <literal>/run/phpfpm-piwik.sock</literal> fastcgi unix socket.
9292- You can use the nginx configuration in the module code as a reference to what else should be configured.
9393- </para>
9494- </section>
9595-</chapter>
···11{ config, lib, pkgs, services, ... }:
22with lib;
33let
44- cfg = config.services.piwik;
44+ cfg = config.services.matomo;
5566- user = "piwik";
66+ user = "matomo";
77 dataDir = "/var/lib/${user}";
88+ deprecatedDataDir = "/var/lib/piwik";
89910 pool = user;
1011 # it's not possible to use /run/phpfpm/${pool}.sock because /run/phpfpm/ is root:root 0770,
···15161617in {
1718 options = {
1818- services.piwik = {
1919+ services.matomo = {
1920 # NixOS PR for database setup: https://github.com/NixOS/nixpkgs/pull/6963
2020- # piwik issue for automatic piwik setup: https://github.com/piwik/piwik/issues/10257
2121- # TODO: find a nice way to do this when more NixOS MySQL and / or piwik automatic setup stuff is implemented.
2121+ # matomo issue for automatic matomo setup: https://github.com/matomo-org/matomo/issues/10257
2222+ # TODO: find a nice way to do this when more NixOS MySQL and / or matomo automatic setup stuff is implemented.
2223 enable = mkOption {
2324 type = types.bool;
2425 default = false;
2526 description = ''
2626- Enable piwik web analytics with php-fpm backend.
2727+ Enable matomo web analytics with php-fpm backend.
2728 Either the nginx option or the webServerUser option is mandatory.
2829 '';
2930 };
···3233 type = types.nullOr types.str;
3334 default = null;
3435 example = "lighttpd";
3636+ # TODO: piwik.php might get renamed to matomo.php in future releases
3537 description = ''
3636- Name of the web server user that forwards requests to the ${phpSocket} fastcgi socket for piwik if the nginx
3838+ Name of the web server user that forwards requests to the ${phpSocket} fastcgi socket for matomo if the nginx
3739 option is not used. Either this option or the nginx option is mandatory.
3840 If you want to use another webserver than nginx, you need to set this to that server's user
3941 and pass fastcgi requests to `index.php` and `piwik.php` to this socket.
···5557 catch_workers_output = yes
5658 '';
5759 description = ''
5858- Settings for phpfpm's process manager. You might need to change this depending on the load for piwik.
6060+ Settings for phpfpm's process manager. You might need to change this depending on the load for matomo.
5961 '';
6062 };
6163···6567 (import ../web-servers/nginx/vhost-options.nix { inherit config lib; })
6668 {
6769 # enable encryption by default,
6868- # as sensitive login and piwik data should not be transmitted in clear text.
7070+ # as sensitive login and matomo data should not be transmitted in clear text.
6971 options.forceSSL.default = true;
7072 options.enableACME.default = true;
7173 }
···7779 enableACME = false;
7880 };
7981 description = ''
8080- With this option, you can customize an nginx virtualHost which already has sensible defaults for piwik.
8282+ With this option, you can customize an nginx virtualHost which already has sensible defaults for matomo.
8183 Either this option or the webServerUser option is mandatory.
8284 Set this to {} to just enable the virtualHost if you don't need any customization.
8383- If enabled, then by default, the serverName is piwik.$\{config.networking.hostName\}, SSL is active,
8585+ If enabled, then by default, the serverName is ${user}.$\{config.networking.hostName\}, SSL is active,
8486 and certificates are acquired via ACME.
8587 If this is set to null (the default), no nginx virtualHost will be configured.
8688 '';
···90929193 config = mkIf cfg.enable {
9294 warnings = mkIf (cfg.nginx != null && cfg.webServerUser != null) [
9393- "If services.piwik.nginx is set, services.piwik.nginx.webServerUser is ignored and should be removed."
9595+ "If services.matomo.nginx is set, services.matomo.nginx.webServerUser is ignored and should be removed."
9496 ];
95979698 assertions = [ {
9799 assertion = cfg.nginx != null || cfg.webServerUser != null;
9898- message = "Either services.piwik.nginx or services.piwik.nginx.webServerUser is mandatory";
100100+ message = "Either services.matomo.nginx or services.matomo.nginx.webServerUser is mandatory";
99101 }];
100102101103 users.extraUsers.${user} = {
···106108 };
107109 users.extraGroups.${user} = {};
108110109109- systemd.services.piwik_setup_update = {
110110- # everything needs to set up and up to date before piwik php files are executed
111111+ systemd.services.matomo_setup_update = {
112112+ # everything needs to set up and up to date before matomo php files are executed
111113 requiredBy = [ "${phpExecutionUnit}.service" ];
112114 before = [ "${phpExecutionUnit}.service" ];
113115 # the update part of the script can only work if the database is already up and running
114116 requires = [ databaseService ];
115117 after = [ databaseService ];
116116- path = [ pkgs.piwik ];
118118+ path = [ pkgs.matomo ];
117119 serviceConfig = {
118120 Type = "oneshot";
119121 User = user;
120122 # hide especially config.ini.php from other
121123 UMask = "0007";
124124+ # TODO: might get renamed to MATOMO_USER_PATH in future versions
122125 Environment = "PIWIK_USER_PATH=${dataDir}";
123126 # chown + chmod in preStart needs root
124127 PermissionsStartOnly = true;
···127130 # e.g. after restoring from backup or moving from another system.
128131 # Note that ${dataDir}/config/config.ini.php might contain the MySQL password.
129132 preStart = ''
133133+ # migrate data from piwik to matomo folder
134134+ if [ -d ${deprecatedDataDir} ]; then
135135+ echo "Migrating from ${deprecatedDataDir} to ${dataDir}"
136136+ mv -T ${deprecatedDataDir} ${dataDir}
137137+ fi
130138 chown -R ${user}:${user} ${dataDir}
131139 chmod -R ug+rwX,o-rwx ${dataDir}
132140 '';
133141 script = ''
134134- # Use User-Private Group scheme to protect piwik data, but allow administration / backup via piwik group
142142+ # Use User-Private Group scheme to protect matomo data, but allow administration / backup via matomo group
135143 # Copy config folder
136144 chmod g+s "${dataDir}"
137137- cp -r "${pkgs.piwik}/config" "${dataDir}/"
145145+ cp -r "${pkgs.matomo}/config" "${dataDir}/"
138146 chmod -R u+rwX,g+rwX,o-rwx "${dataDir}"
139147140148 # check whether user setup has already been done
141149 if test -f "${dataDir}/config/config.ini.php"; then
142150 # then execute possibly pending database upgrade
143143- piwik-console core:update --yes
151151+ matomo-console core:update --yes
144152 fi
145153 '';
146154 };
147155148156 systemd.services.${phpExecutionUnit} = {
149149- # stop phpfpm on package upgrade, do database upgrade via piwik_setup_update, and then restart
150150- restartTriggers = [ pkgs.piwik ];
157157+ # stop phpfpm on package upgrade, do database upgrade via matomo_setup_update, and then restart
158158+ restartTriggers = [ pkgs.matomo ];
151159 # stop config.ini.php from getting written with read permission for others
152160 serviceConfig.UMask = "0007";
153161 };
···175183 # References:
176184 # https://fralef.me/piwik-hardening-with-nginx-and-php-fpm.html
177185 # https://github.com/perusio/piwik-nginx
186186+ # TODO: better default
178187 "${user}.${config.networking.hostName}" = mkMerge [ cfg.nginx {
179179- # don't allow to override the root easily, as it will almost certainly break piwik.
188188+ # don't allow to override the root easily, as it will almost certainly break matomo.
180189 # disadvantage: not shown as default in docs.
181181- root = mkForce "${pkgs.piwik}/share";
190190+ root = mkForce "${pkgs.matomo}/share";
182191183192 # define locations here instead of as the submodule option's default
184193 # so that they can easily be extended with additional locations if required
185185- # without needing to redefine the piwik ones.
194194+ # without needing to redefine the matomo ones.
186195 # disadvantage: not shown as default in docs.
187196 locations."/" = {
188197 index = "index.php";
···191200 locations."= /index.php".extraConfig = ''
192201 fastcgi_pass unix:${phpSocket};
193202 '';
203203+ # TODO: might get renamed to matomo.php in future versions
194204 # allow piwik.php for tracking
195205 locations."= /piwik.php".extraConfig = ''
196206 fastcgi_pass unix:${phpSocket};
···212222 locations."= /robots.txt".extraConfig = ''
213223 return 200 "User-agent: *\nDisallow: /\n";
214224 '';
225225+ # TODO: might get renamed to matomo.js in future versions
215226 # let browsers cache piwik.js
216227 locations."= /piwik.js".extraConfig = ''
217228 expires 1M;
···221232 };
222233223234 meta = {
224224- doc = ./piwik-doc.xml;
235235+ doc = ./matomo-doc.xml;
225236 maintainers = with stdenv.lib.maintainers; [ florianjacob ];
226237 };
227238}