···244244 <link xlink:href="http://borgbackup.readthedocs.io/en/stable/usage/upgrade.html#attic-and-borg-0-xx-to-borg-1-x">here</link>.
245245 </para>
246246 </listitem>
247247+ <listitem>
248248+ <para>
249249+ The Piwik analytics software was renamed to Matomo:
250250+ <itemizedlist>
251251+ <listitem>
252252+ <para>The package <literal>pkgs.piwik</literal> was renamed to <literal>pkgs.matomo</literal>.</para>
253253+ </listitem>
254254+ <listitem>
255255+ <para>The service <literal>services.piwik</literal> was renamed to <literal>services.matomo</literal>.</para>
256256+ </listitem>
257257+ <listitem>
258258+ <para>
259259+ The data directory <filename>/var/lib/piwik</filename> was renamed to <filename>/var/lib/matomo</filename>.
260260+ All files will be moved automatically on first startup, but you might need to adjust your backup scripts.
261261+ </para>
262262+ </listitem>
263263+ <listitem>
264264+ <para>
265265+ The default <option>serverName</option> for the nginx configuration changed from
266266+ <literal>piwik.${config.networking.hostName}</literal> to
267267+ <literal>matomo.${config.networking.hostName}.${config.networking.domain}</literal>
268268+ if <option>config.networking.domain</option> is set,
269269+ <literal>matomo.${config.networking.hostName}</literal> if it is not set.
270270+ If you change your <option>serverName</option>, remember you'll need to update the
271271+ <literal>trustedHosts[]</literal> array in <filename>/var/lib/matomo/config/config.ini.php</filename>
272272+ as well.
273273+ </para>
274274+ </listitem>
275275+ <listitem>
276276+ <para>
277277+ The <literal>piwik</literal> user was renamed to <literal>matomo</literal>.
278278+ The service will adjust ownership automatically for files in the data directory.
279279+ If you use unix socket authentication, remember to give the new <literal>matomo</literal> user
280280+ access to the database and to change the <literal>username</literal> to <literal>matomo</literal>
281281+ in the <literal>[database]</literal> section of <filename>/var/lib/matomo/config/config.ini.php</filename>.
282282+ </para>
283283+ </listitem>
284284+ <listitem>
285285+ <para>
286286+ If you named your database `piwik`, you might want to rename it to `matomo` to keep things clean,
287287+ but this is neither enforced nor required.
288288+ </para>
289289+ </listitem>
290290+ </itemizedlist>
291291+ </para>
292292+ </listitem>
247293</itemizedlist>
248294249295</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,
···1213 phpSocket = "/run/phpfpm-${pool}.sock";
1314 phpExecutionUnit = "phpfpm-${pool}";
1415 databaseService = "mysql.service";
1616+1717+ fqdn =
1818+ let
1919+ join = hostName: domain: hostName + optionalString (domain != null) ".${domain}";
2020+ in join config.networking.hostName config.networking.domain;
15211622in {
1723 options = {
1818- services.piwik = {
2424+ services.matomo = {
1925 # 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.
2626+ # matomo issue for automatic matomo setup: https://github.com/matomo-org/matomo/issues/10257
2727+ # TODO: find a nice way to do this when more NixOS MySQL and / or matomo automatic setup stuff is implemented.
2228 enable = mkOption {
2329 type = types.bool;
2430 default = false;
2531 description = ''
2626- Enable piwik web analytics with php-fpm backend.
3232+ Enable matomo web analytics with php-fpm backend.
2733 Either the nginx option or the webServerUser option is mandatory.
2834 '';
2935 };
···3238 type = types.nullOr types.str;
3339 default = null;
3440 example = "lighttpd";
4141+ # TODO: piwik.php might get renamed to matomo.php in future releases
3542 description = ''
3636- Name of the web server user that forwards requests to the ${phpSocket} fastcgi socket for piwik if the nginx
4343+ Name of the web server user that forwards requests to the ${phpSocket} fastcgi socket for matomo if the nginx
3744 option is not used. Either this option or the nginx option is mandatory.
3845 If you want to use another webserver than nginx, you need to set this to that server's user
3946 and pass fastcgi requests to `index.php` and `piwik.php` to this socket.
···5562 catch_workers_output = yes
5663 '';
5764 description = ''
5858- Settings for phpfpm's process manager. You might need to change this depending on the load for piwik.
6565+ Settings for phpfpm's process manager. You might need to change this depending on the load for matomo.
5966 '';
6067 };
6168···6572 (import ../web-servers/nginx/vhost-options.nix { inherit config lib; })
6673 {
6774 # enable encryption by default,
6868- # as sensitive login and piwik data should not be transmitted in clear text.
7575+ # as sensitive login and matomo data should not be transmitted in clear text.
6976 options.forceSSL.default = true;
7077 options.enableACME.default = true;
7178 }
···7380 );
7481 default = null;
7582 example = {
7676- serverName = "stats.$\{config.networking.hostName\}";
8383+ serverAliases = [
8484+ "matomo.$\{config.networking.domain\}"
8585+ "stats.$\{config.networking.domain\}"
8686+ ];
7787 enableACME = false;
7888 };
7989 description = ''
8080- With this option, you can customize an nginx virtualHost which already has sensible defaults for piwik.
9090+ With this option, you can customize an nginx virtualHost which already has sensible defaults for matomo.
8191 Either this option or the webServerUser option is mandatory.
8292 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,
8484- and certificates are acquired via ACME.
9393+ If enabled, then by default, the <option>serverName</option> is
9494+ <literal>${user}.$\{config.networking.hostName\}.$\{config.networking.domain\}</literal>,
9595+ SSL is active, and certificates are acquired via ACME.
8596 If this is set to null (the default), no nginx virtualHost will be configured.
8697 '';
8798 };
···9010191102 config = mkIf cfg.enable {
92103 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."
104104+ "If services.matomo.nginx is set, services.matomo.nginx.webServerUser is ignored and should be removed."
94105 ];
9510696107 assertions = [ {
97108 assertion = cfg.nginx != null || cfg.webServerUser != null;
9898- message = "Either services.piwik.nginx or services.piwik.nginx.webServerUser is mandatory";
109109+ message = "Either services.matomo.nginx or services.matomo.nginx.webServerUser is mandatory";
99110 }];
100111101112 users.extraUsers.${user} = {
···106117 };
107118 users.extraGroups.${user} = {};
108119109109- systemd.services.piwik_setup_update = {
110110- # everything needs to set up and up to date before piwik php files are executed
120120+ systemd.services.matomo_setup_update = {
121121+ # everything needs to set up and up to date before matomo php files are executed
111122 requiredBy = [ "${phpExecutionUnit}.service" ];
112123 before = [ "${phpExecutionUnit}.service" ];
113124 # the update part of the script can only work if the database is already up and running
114125 requires = [ databaseService ];
115126 after = [ databaseService ];
116116- path = [ pkgs.piwik ];
127127+ path = [ pkgs.matomo ];
117128 serviceConfig = {
118129 Type = "oneshot";
119130 User = user;
120131 # hide especially config.ini.php from other
121132 UMask = "0007";
133133+ # TODO: might get renamed to MATOMO_USER_PATH in future versions
122134 Environment = "PIWIK_USER_PATH=${dataDir}";
123135 # chown + chmod in preStart needs root
124136 PermissionsStartOnly = true;
···127139 # e.g. after restoring from backup or moving from another system.
128140 # Note that ${dataDir}/config/config.ini.php might contain the MySQL password.
129141 preStart = ''
142142+ # migrate data from piwik to matomo folder
143143+ if [ -d ${deprecatedDataDir} ]; then
144144+ echo "Migrating from ${deprecatedDataDir} to ${dataDir}"
145145+ mv -T ${deprecatedDataDir} ${dataDir}
146146+ fi
130147 chown -R ${user}:${user} ${dataDir}
131148 chmod -R ug+rwX,o-rwx ${dataDir}
132149 '';
133150 script = ''
134134- # Use User-Private Group scheme to protect piwik data, but allow administration / backup via piwik group
151151+ # Use User-Private Group scheme to protect matomo data, but allow administration / backup via matomo group
135152 # Copy config folder
136153 chmod g+s "${dataDir}"
137137- cp -r "${pkgs.piwik}/config" "${dataDir}/"
154154+ cp -r "${pkgs.matomo}/config" "${dataDir}/"
138155 chmod -R u+rwX,g+rwX,o-rwx "${dataDir}"
139156140157 # check whether user setup has already been done
141158 if test -f "${dataDir}/config/config.ini.php"; then
142159 # then execute possibly pending database upgrade
143143- piwik-console core:update --yes
160160+ matomo-console core:update --yes
144161 fi
145162 '';
146163 };
147164148165 systemd.services.${phpExecutionUnit} = {
149149- # stop phpfpm on package upgrade, do database upgrade via piwik_setup_update, and then restart
150150- restartTriggers = [ pkgs.piwik ];
166166+ # stop phpfpm on package upgrade, do database upgrade via matomo_setup_update, and then restart
167167+ restartTriggers = [ pkgs.matomo ];
151168 # stop config.ini.php from getting written with read permission for others
152169 serviceConfig.UMask = "0007";
153170 };
···175192 # References:
176193 # https://fralef.me/piwik-hardening-with-nginx-and-php-fpm.html
177194 # https://github.com/perusio/piwik-nginx
178178- "${user}.${config.networking.hostName}" = mkMerge [ cfg.nginx {
179179- # don't allow to override the root easily, as it will almost certainly break piwik.
195195+ "${user}.${fqdn}" = mkMerge [ cfg.nginx {
196196+ # don't allow to override the root easily, as it will almost certainly break matomo.
180197 # disadvantage: not shown as default in docs.
181181- root = mkForce "${pkgs.piwik}/share";
198198+ root = mkForce "${pkgs.matomo}/share";
182199183200 # define locations here instead of as the submodule option's default
184201 # so that they can easily be extended with additional locations if required
185185- # without needing to redefine the piwik ones.
202202+ # without needing to redefine the matomo ones.
186203 # disadvantage: not shown as default in docs.
187204 locations."/" = {
188205 index = "index.php";
···191208 locations."= /index.php".extraConfig = ''
192209 fastcgi_pass unix:${phpSocket};
193210 '';
211211+ # TODO: might get renamed to matomo.php in future versions
194212 # allow piwik.php for tracking
195213 locations."= /piwik.php".extraConfig = ''
196214 fastcgi_pass unix:${phpSocket};
···212230 locations."= /robots.txt".extraConfig = ''
213231 return 200 "User-agent: *\nDisallow: /\n";
214232 '';
233233+ # TODO: might get renamed to matomo.js in future versions
215234 # let browsers cache piwik.js
216235 locations."= /piwik.js".extraConfig = ''
217236 expires 1M;
···221240 };
222241223242 meta = {
224224- doc = ./piwik-doc.xml;
243243+ doc = ./matomo-doc.xml;
225244 maintainers = with stdenv.lib.maintainers; [ florianjacob ];
226245 };
227246}
+59
pkgs/servers/web-apps/matomo/default.nix
···11+{ stdenv, fetchurl, makeWrapper, php }:
22+33+stdenv.mkDerivation rec {
44+ name = "matomo-${version}";
55+ version = "3.3.0";
66+77+ src = fetchurl {
88+ # TODO: As soon as the tarballs are renamed as well on future releases, this should be enabled again
99+ # url = "https://builds.matomo.org/${name}.tar.gz";
1010+ url = "https://builds.matomo.org/piwik-${version}.tar.gz";
1111+ sha256 = "1ybzj3kk0x29nv8c6xnhir5d9dr0q0fl1vnm4i7zvhml73ryqk0f";
1212+ };
1313+1414+ nativeBuildInputs = [ makeWrapper ];
1515+1616+ # make-localhost-default-database-server.patch:
1717+ # This changes the default value of the database server field
1818+ # from 127.0.0.1 to localhost.
1919+ # unix socket authentication only works with localhost,
2020+ # but password-based SQL authentication works with both.
2121+ # TODO: is upstream interested in this?
2222+ patches = [ ./make-localhost-default-database-host.patch ];
2323+2424+ # this bootstrap.php adds support for getting PIWIK_USER_PATH
2525+ # from an environment variable. Point it to a mutable location
2626+ # to be able to use matomo read-only from the nix store
2727+ postPatch = ''
2828+ cp ${./bootstrap.php} bootstrap.php
2929+ '';
3030+3131+ # TODO: future versions might rename the PIWIK_… variables to MATOMO_…
3232+ # TODO: Move more unnecessary files from share/, especially using PIWIK_INCLUDE_PATH.
3333+ # See https://forum.matomo.org/t/bootstrap-php/5926/10 and
3434+ # https://github.com/matomo-org/matomo/issues/11654#issuecomment-297730843
3535+ installPhase = ''
3636+ runHook preInstall
3737+3838+ # copy evertything to share/, used as webroot folder, and then remove what's known to be not needed
3939+ mkdir -p $out/share
4040+ cp -ra * $out/share/
4141+ # tmp/ is created by matomo in PIWIK_USER_PATH
4242+ rmdir $out/share/tmp
4343+ # config/ needs to be copied to PIWIK_USER_PATH anyway
4444+ mv $out/share/config $out/
4545+4646+ makeWrapper ${php}/bin/php $out/bin/matomo-console \
4747+ --add-flags "$out/share/console"
4848+4949+ runHook postInstall
5050+ '';
5151+5252+ meta = with stdenv.lib; {
5353+ description = "A real-time web analytics application";
5454+ license = licenses.gpl3Plus;
5555+ homepage = https://matomo.org/;
5656+ platforms = platforms.all;
5757+ maintainers = [ maintainers.florianjacob ];
5858+ };
5959+}