matomo: refactor into single package file

This commit is contained in:
Niklas Korz 2025-01-15 11:47:35 +01:00
parent d7ac52bd81
commit 83eb8d8020
3 changed files with 156 additions and 181 deletions

View file

@ -5,71 +5,61 @@
}: }:
with import ../lib/testing-python.nix { inherit system pkgs; }; with import ../lib/testing-python.nix { inherit system pkgs; };
with pkgs.lib;
let makeTest {
matomoTest = name = "matomo";
package:
makeTest {
name = "matomo";
nodes.machine = nodes.machine =
{ config, pkgs, ... }: { config, pkgs, ... }:
{ {
services.matomo = { services.matomo = {
package = package; enable = true;
enable = true; nginx = {
nginx = { forceSSL = false;
forceSSL = false; enableACME = false;
enableACME = false;
};
};
services.mysql = {
enable = true;
package = pkgs.mariadb;
};
services.nginx.enable = true;
}; };
};
testScript = '' services.mysql = {
start_all() enable = true;
machine.wait_for_unit("mysql.service") package = pkgs.mariadb;
machine.wait_for_unit("phpfpm-matomo.service") };
machine.wait_for_unit("nginx.service") services.nginx.enable = true;
with subtest("matomo.js reachable via HTTP"):
machine.succeed("curl -sSfk http://machine/matomo.js")
with subtest("js/piwik.js reachable via HTTP"):
machine.succeed("curl -sSfk http://machine/js/piwik.js")
with subtest("matomo.php (API) reachable via HTTP"):
machine.succeed("curl -sSfk http://machine/matomo.php")
# without the grep the command does not produce valid utf-8 for some reason
with subtest("welcome screen loads"):
machine.succeed(
"curl -sSfL http://localhost/ | grep '<title>Matomo[^<]*Installation'"
)
with subtest("killing the phpfpm process should trigger an automatic restart"):
machine.succeed("systemctl kill -s KILL phpfpm-matomo")
machine.sleep(1)
machine.wait_for_unit("phpfpm-matomo.service")
'';
}; };
in
{ testScript = ''
matomo = matomoTest pkgs.matomo // { start_all()
name = "matomo"; machine.wait_for_unit("mysql.service")
meta.maintainers = machine.wait_for_unit("phpfpm-matomo.service")
with maintainers; machine.wait_for_unit("nginx.service")
[
florianjacob with subtest("matomo.js reachable via HTTP"):
mmilata machine.succeed("curl -sSfk http://machine/matomo.js")
twey
boozedog with subtest("js/piwik.js reachable via HTTP"):
] machine.succeed("curl -sSfk http://machine/js/piwik.js")
++ lib.teams.flyingcircus.members;
}; with subtest("matomo.php (API) reachable via HTTP"):
machine.succeed("curl -sSfk http://machine/matomo.php")
# without the grep the command does not produce valid utf-8 for some reason
with subtest("welcome screen loads"):
machine.succeed(
"curl -sSfL http://localhost/ | grep '<title>Matomo[^<]*Installation'"
)
with subtest("killing the phpfpm process should trigger an automatic restart"):
machine.succeed("systemctl kill -s KILL phpfpm-matomo")
machine.sleep(1)
machine.wait_for_unit("phpfpm-matomo.service")
'';
meta.maintainers =
with pkgs.lib.maintainers;
[
florianjacob
mmilata
twey
boozedog
]
++ pkgs.lib.teams.flyingcircus.members;
} }

View file

@ -7,122 +7,108 @@
nixosTests, nixosTests,
}: }:
let stdenv.mkDerivation (finalAttrs: {
versions = { pname = "matomo";
matomo = { version = "5.2.1";
version = "5.2.1";
hash = "sha256-5glMwwIG0Uo8bu904u40FUa+yaUlrQe1nUCkv9/ATks="; src = fetchurl {
url = "https://builds.matomo.org/matomo-${finalAttrs.version}.tar.gz";
hash = "sha256-5glMwwIG0Uo8bu904u40FUa+yaUlrQe1nUCkv9/ATks=";
};
nativeBuildInputs = [ makeWrapper ];
patches = [
# This changes the default value of the database server field
# from 127.0.0.1 to localhost.
# unix socket authentication only works with localhost,
# but password-based SQL authentication works with both.
# TODO: is upstream interested in this?
# -> discussion at https://github.com/matomo-org/matomo/issues/12646
./make-localhost-default-database-host.patch
# This changes the default config for path.geoip2 so that it doesn't point
# to the nix store.
./change-path-geoip2-5.x.patch
];
# this bootstrap.php adds support for getting PIWIK_USER_PATH
# from an environment variable. Point it to a mutable location
# to be able to use matomo read-only from the nix store
postPatch = ''
cp ${./bootstrap.php} bootstrap.php
'';
# TODO: future versions might rename the PIWIK_… variables to MATOMO_…
# TODO: Move more unnecessary files from share/, especially using PIWIK_INCLUDE_PATH.
# See https://forum.matomo.org/t/bootstrap-php/5926/10 and
# https://github.com/matomo-org/matomo/issues/11654#issuecomment-297730843
installPhase = ''
runHook preInstall
# copy everything to share/, used as webroot folder, and then remove what's known to be not needed
mkdir -p $out/share
cp -ra * $out/share/
# tmp/ is created by matomo in PIWIK_USER_PATH
rmdir $out/share/tmp
# config/ needs to be accessed by PIWIK_USER_PATH anyway
ln -s $out/share/config $out/
makeWrapper ${php}/bin/php $out/bin/matomo-console \
--add-flags "$out/share/console"
runHook postInstall
'';
filesToFix = [
"misc/composer/build-xhprof.sh"
"misc/composer/clean-xhprof.sh"
"misc/cron/archive.sh"
"plugins/GeoIp2/config/config.php"
"plugins/Installation/FormDatabaseSetup.php"
"vendor/pear/archive_tar/sync-php4"
"vendor/szymach/c-pchart/coverage.sh"
"vendor/matomo/matomo-php-tracker/run_tests.sh"
"vendor/twig/twig/drupal_test.sh"
];
# This fixes the consistency check in the admin interface
#
# The filesToFix list may contain files that are exclusive to only one of the versions we build
# make sure to test for existence to avoid erroring on an incompatible version and failing
postFixup = ''
pushd $out/share > /dev/null
for f in $filesToFix; do
if [ -f "$f" ]; then
length="$(wc -c "$f" | cut -d' ' -f1)"
hash="$(md5sum "$f" | cut -d' ' -f1)"
sed -i "s:\\(\"$f\"[^(]*(\\).*:\\1\"$length\", \"$hash\"),:g" config/manifest.inc.php
else
echo "INFO(files-to-fix): $f does not exist in this version"
fi
done
popd > /dev/null
'';
passthru = {
tests = lib.optionalAttrs stdenv.hostPlatform.isLinux {
inherit (nixosTests) matomo;
}; };
}; };
common =
pname:
{
version,
hash,
beta ? null,
}:
stdenv.mkDerivation (finalAttrs: {
name = "${pname}-${finalAttrs.version}";
version = version + lib.optionalString (beta != null) "-${toString beta}";
src = fetchurl { meta = with lib; {
url = "https://builds.matomo.org/matomo-${finalAttrs.version}.tar.gz"; description = "Real-time web analytics application";
inherit hash; mainProgram = "matomo-console";
}; license = licenses.gpl3Plus;
homepage = "https://matomo.org/";
nativeBuildInputs = [ makeWrapper ]; platforms = platforms.all;
maintainers =
patches = [ with maintainers;
# This changes the default value of the database server field [
# from 127.0.0.1 to localhost. florianjacob
# unix socket authentication only works with localhost, sebbel
# but password-based SQL authentication works with both. twey
# TODO: is upstream interested in this? boozedog
# -> discussion at https://github.com/matomo-org/matomo/issues/12646 ]
./make-localhost-default-database-host.patch ++ teams.flyingcircus.members;
# This changes the default config for path.geoip2 so that it doesn't point };
# to the nix store. })
./change-path-geoip2-5.x.patch
];
# this bootstrap.php adds support for getting PIWIK_USER_PATH
# from an environment variable. Point it to a mutable location
# to be able to use matomo read-only from the nix store
postPatch = ''
cp ${./bootstrap.php} bootstrap.php
'';
# TODO: future versions might rename the PIWIK_… variables to MATOMO_…
# TODO: Move more unnecessary files from share/, especially using PIWIK_INCLUDE_PATH.
# See https://forum.matomo.org/t/bootstrap-php/5926/10 and
# https://github.com/matomo-org/matomo/issues/11654#issuecomment-297730843
installPhase = ''
runHook preInstall
# copy everything to share/, used as webroot folder, and then remove what's known to be not needed
mkdir -p $out/share
cp -ra * $out/share/
# tmp/ is created by matomo in PIWIK_USER_PATH
rmdir $out/share/tmp
# config/ needs to be accessed by PIWIK_USER_PATH anyway
ln -s $out/share/config $out/
makeWrapper ${php}/bin/php $out/bin/matomo-console \
--add-flags "$out/share/console"
runHook postInstall
'';
filesToFix = [
"misc/composer/build-xhprof.sh"
"misc/composer/clean-xhprof.sh"
"misc/cron/archive.sh"
"plugins/GeoIp2/config/config.php"
"plugins/Installation/FormDatabaseSetup.php"
"vendor/pear/archive_tar/sync-php4"
"vendor/szymach/c-pchart/coverage.sh"
"vendor/matomo/matomo-php-tracker/run_tests.sh"
"vendor/twig/twig/drupal_test.sh"
];
# This fixes the consistency check in the admin interface
#
# The filesToFix list may contain files that are exclusive to only one of the versions we build
# make sure to test for existence to avoid erroring on an incompatible version and failing
postFixup = ''
pushd $out/share > /dev/null
for f in $filesToFix; do
if [ -f "$f" ]; then
length="$(wc -c "$f" | cut -d' ' -f1)"
hash="$(md5sum "$f" | cut -d' ' -f1)"
sed -i "s:\\(\"$f\"[^(]*(\\).*:\\1\"$length\", \"$hash\"),:g" config/manifest.inc.php
else
echo "INFO(files-to-fix): $f does not exist in this version"
fi
done
popd > /dev/null
'';
passthru = {
tests = nixosTests.matomo."${pname}";
};
meta = with lib; {
description = "Real-time web analytics application";
mainProgram = "matomo-console";
license = licenses.gpl3Plus;
homepage = "https://matomo.org/";
platforms = platforms.all;
maintainers =
with maintainers;
[
florianjacob
sebbel
twey
boozedog
]
++ teams.flyingcircus.members;
};
});
in
lib.mapAttrs common versions

View file

@ -11882,8 +11882,7 @@ with pkgs;
}; };
tt-rss = callPackage ../servers/tt-rss { }; tt-rss = callPackage ../servers/tt-rss { };
inherit (callPackages ../servers/web-apps/matomo {}) matomo = callPackage ../servers/web-apps/matomo { };
matomo;
unpackerr = callPackage ../servers/unpackerr { unpackerr = callPackage ../servers/unpackerr {
inherit (darwin.apple_sdk.frameworks) Cocoa WebKit; inherit (darwin.apple_sdk.frameworks) Cocoa WebKit;