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

+34 -5
+20
nixos/modules/services/continuous-integration/hydra/default.nix
··· 275 ${pkgs.sudo}/bin/sudo -u ${config.services.postgresql.superUser} ${config.services.postgresql.package}/bin/createdb -O hydra hydra 276 touch ${baseDir}/.db-created 277 fi 278 ''} 279 280 if [ ! -e ${cfg.gcRootsDir} ]; then ··· 379 }; 380 }; 381 382 # If there is less than a certain amount of free disk space, stop 383 # the queue/evaluator to prevent builds from failing or aborting. 384 systemd.services.hydra-check-space = ··· 416 hydra-users hydra-queue-runner hydra 417 hydra-users hydra-www hydra 418 hydra-users root hydra 419 ''; 420 421 services.postgresql.authentication = optionalString haveLocalDB
··· 275 ${pkgs.sudo}/bin/sudo -u ${config.services.postgresql.superUser} ${config.services.postgresql.package}/bin/createdb -O hydra hydra 276 touch ${baseDir}/.db-created 277 fi 278 + echo "create extension if not exists pg_trgm" | ${pkgs.sudo}/bin/sudo -u ${config.services.postgresql.superUser} -- ${config.services.postgresql.package}/bin/psql hydra 279 ''} 280 281 if [ ! -e ${cfg.gcRootsDir} ]; then ··· 380 }; 381 }; 382 383 + systemd.services.hydra-notify = 384 + { wantedBy = [ "multi-user.target" ]; 385 + requires = [ "hydra-init.service" ]; 386 + after = [ "hydra-init.service" ]; 387 + restartTriggers = [ hydraConf ]; 388 + environment = env // { 389 + PGPASSFILE = "${baseDir}/pgpass-queue-runner"; 390 + }; 391 + serviceConfig = 392 + { ExecStart = "@${cfg.package}/bin/hydra-notify hydra-notify"; 393 + # FIXME: run this under a less privileged user? 394 + User = "hydra-queue-runner"; 395 + Restart = "always"; 396 + RestartSec = 5; 397 + }; 398 + }; 399 + 400 # If there is less than a certain amount of free disk space, stop 401 # the queue/evaluator to prevent builds from failing or aborting. 402 systemd.services.hydra-check-space = ··· 434 hydra-users hydra-queue-runner hydra 435 hydra-users hydra-www hydra 436 hydra-users root hydra 437 + # The postgres user is used to create the pg_trgm extension for the hydra database 438 + hydra-users postgres postgres 439 ''; 440 441 services.postgresql.authentication = optionalString haveLocalDB
+2
nixos/tests/hydra/create-trivial-project.sh
··· 44 "enabled": "1", 45 "visible": "1", 46 "keepnr": "1", 47 "nixexprinput": "trivial", 48 "nixexprpath": "trivial.nix", 49 "inputs": {
··· 44 "enabled": "1", 45 "visible": "1", 46 "keepnr": "1", 47 + "enableemail": true, 48 + "emailoverride": "hydra@localhost", 49 "nixexprinput": "trivial", 50 "nixexprpath": "trivial.nix", 51 "inputs": {
+12 -5
nixos/tests/hydra/default.nix
··· 55 notificationSender = "example@example.com"; 56 57 package = pkgs.hydra.override { inherit nix; }; 58 }; 59 nix = { 60 buildMachines = [{ 61 hostName = "localhost"; ··· 70 # let the system boot up 71 $machine->waitForUnit("multi-user.target"); 72 # test whether the database is running 73 - $machine->succeed("systemctl status postgresql.service"); 74 # test whether the actual hydra daemons are running 75 - $machine->succeed("systemctl status hydra-queue-runner.service"); 76 - $machine->succeed("systemctl status hydra-init.service"); 77 - $machine->succeed("systemctl status hydra-evaluator.service"); 78 - $machine->succeed("systemctl status hydra-send-stats.service"); 79 80 $machine->succeed("hydra-create-user admin --role admin --password admin"); 81 ··· 86 $machine->succeed("create-trivial-project.sh"); 87 88 $machine->waitUntilSucceeds('curl -L -s http://localhost:3000/build/1 -H "Accept: application/json" | jq .buildstatus | xargs test 0 -eq'); 89 ''; 90 }))); 91
··· 55 notificationSender = "example@example.com"; 56 57 package = pkgs.hydra.override { inherit nix; }; 58 + 59 + extraConfig = '' 60 + email_notification = 1 61 + ''; 62 }; 63 + services.postfix.enable = true; 64 nix = { 65 buildMachines = [{ 66 hostName = "localhost"; ··· 75 # let the system boot up 76 $machine->waitForUnit("multi-user.target"); 77 # test whether the database is running 78 + $machine->waitForUnit("postgresql.service"); 79 # test whether the actual hydra daemons are running 80 + $machine->waitForUnit("hydra-init.service"); 81 + $machine->requireActiveUnit("hydra-queue-runner.service"); 82 + $machine->requireActiveUnit("hydra-evaluator.service"); 83 + $machine->requireActiveUnit("hydra-notify.service"); 84 85 $machine->succeed("hydra-create-user admin --role admin --password admin"); 86 ··· 91 $machine->succeed("create-trivial-project.sh"); 92 93 $machine->waitUntilSucceeds('curl -L -s http://localhost:3000/build/1 -H "Accept: application/json" | jq .buildstatus | xargs test 0 -eq'); 94 + 95 + $machine->waitUntilSucceeds('journalctl -eu hydra-notify.service -o cat | grep -q "sending mail notification to hydra@localhost"'); 96 ''; 97 }))); 98