nixos/hydra: incorporate upstream changes and update test

During the last update, `hydra-notify` was rewritten as a daemon which
listens to postgresql notifications for each build[1]. The module
uses the `hydra-notify.service` unit from upstream's Hydra module and
the VM test ensures that email notifications are sent properly.

Also updated `hydra-init.service` to install `pg_trgm` on a local
database if needed[2].

[1] https://github.com/NixOS/hydra/commit/c7861b85c4c3cc974b27147bbf3cc258b9fe9cc3
[2] https://github.com/NixOS/hydra/commit/8a0a5ec3a3200d4f4d4d38f87d0afdb49f092b39

Changed files
+34 -5
nixos
modules
services
continuous-integration
hydra
tests
+20
nixos/modules/services/continuous-integration/hydra/default.nix
···
${pkgs.sudo}/bin/sudo -u ${config.services.postgresql.superUser} ${config.services.postgresql.package}/bin/createdb -O hydra hydra
touch ${baseDir}/.db-created
fi
+
echo "create extension if not exists pg_trgm" | ${pkgs.sudo}/bin/sudo -u ${config.services.postgresql.superUser} -- ${config.services.postgresql.package}/bin/psql hydra
''}
if [ ! -e ${cfg.gcRootsDir} ]; then
···
};
};
+
systemd.services.hydra-notify =
+
{ wantedBy = [ "multi-user.target" ];
+
requires = [ "hydra-init.service" ];
+
after = [ "hydra-init.service" ];
+
restartTriggers = [ hydraConf ];
+
environment = env // {
+
PGPASSFILE = "${baseDir}/pgpass-queue-runner";
+
};
+
serviceConfig =
+
{ ExecStart = "@${cfg.package}/bin/hydra-notify hydra-notify";
+
# FIXME: run this under a less privileged user?
+
User = "hydra-queue-runner";
+
Restart = "always";
+
RestartSec = 5;
+
};
+
};
+
# If there is less than a certain amount of free disk space, stop
# the queue/evaluator to prevent builds from failing or aborting.
systemd.services.hydra-check-space =
···
hydra-users hydra-queue-runner hydra
hydra-users hydra-www hydra
hydra-users root hydra
+
# The postgres user is used to create the pg_trgm extension for the hydra database
+
hydra-users postgres postgres
'';
services.postgresql.authentication = optionalString haveLocalDB
+2
nixos/tests/hydra/create-trivial-project.sh
···
"enabled": "1",
"visible": "1",
"keepnr": "1",
+
"enableemail": true,
+
"emailoverride": "hydra@localhost",
"nixexprinput": "trivial",
"nixexprpath": "trivial.nix",
"inputs": {
+12 -5
nixos/tests/hydra/default.nix
···
notificationSender = "example@example.com";
package = pkgs.hydra.override { inherit nix; };
+
+
extraConfig = ''
+
email_notification = 1
+
'';
};
+
services.postfix.enable = true;
nix = {
buildMachines = [{
hostName = "localhost";
···
# let the system boot up
$machine->waitForUnit("multi-user.target");
# test whether the database is running
-
$machine->succeed("systemctl status postgresql.service");
+
$machine->waitForUnit("postgresql.service");
# test whether the actual hydra daemons are running
-
$machine->succeed("systemctl status hydra-queue-runner.service");
-
$machine->succeed("systemctl status hydra-init.service");
-
$machine->succeed("systemctl status hydra-evaluator.service");
-
$machine->succeed("systemctl status hydra-send-stats.service");
+
$machine->waitForUnit("hydra-init.service");
+
$machine->requireActiveUnit("hydra-queue-runner.service");
+
$machine->requireActiveUnit("hydra-evaluator.service");
+
$machine->requireActiveUnit("hydra-notify.service");
$machine->succeed("hydra-create-user admin --role admin --password admin");
···
$machine->succeed("create-trivial-project.sh");
$machine->waitUntilSucceeds('curl -L -s http://localhost:3000/build/1 -H "Accept: application/json" | jq .buildstatus | xargs test 0 -eq');
+
+
$machine->waitUntilSucceeds('journalctl -eu hydra-notify.service -o cat | grep -q "sending mail notification to hydra@localhost"');
'';
})));