From b898c262c1ac38d9b19c22cc07a4f6f9267cfd20 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sun, 8 Sep 2019 01:25:25 +0200 Subject: [PATCH 1/3] hydra: 2019-05-06 -> 2019-08-30 --- pkgs/development/tools/misc/hydra/default.nix | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/pkgs/development/tools/misc/hydra/default.nix b/pkgs/development/tools/misc/hydra/default.nix index 0d50c772bde..4a65d088834 100644 --- a/pkgs/development/tools/misc/hydra/default.nix +++ b/pkgs/development/tools/misc/hydra/default.nix @@ -1,9 +1,9 @@ -{ stdenv, nix, perlPackages, buildEnv, releaseTools, fetchFromGitHub +{ stdenv, nix, perlPackages, buildEnv, fetchFromGitHub , makeWrapper, autoconf, automake, libtool, unzip, pkgconfig, sqlite, libpqxx , gitAndTools, mercurial, darcs, subversion, bazaar, openssl, bzip2, libxslt , guile, perl, postgresql, nukeReferences, git, boehmgc, nlohmann_json , docbook_xsl, openssh, gnused, coreutils, findutils, gzip, lzma, gnutar -, rpm, dpkg, cdrkit, pixz, lib, fetchpatch, boost, autoreconfHook +, rpm, dpkg, cdrkit, pixz, lib, boost, autoreconfHook }: with stdenv; @@ -67,17 +67,17 @@ let boehmgc ]; }; -in releaseTools.nixBuild rec { +in stdenv.mkDerivation rec { pname = "hydra"; - version = "2019-05-06"; + version = "2019-08-30"; inherit stdenv; src = fetchFromGitHub { owner = "NixOS"; repo = pname; - rev = "ff64583d07f046e378a6be596ec0ce7a9e2b7472"; - sha256 = "0w88q0saz7si22z3ryim6vdrv9qkwn6l25xfmiapvh5qrnrrdcb9"; + rev = "242b8b7a314759ed33f69205d26a1b7c337511e0"; + sha256 = "167ijcf9qdm10kjvqax3hcvs5mpa4mx2y2i9idwwc6xfvn8fhs84"; }; buildInputs = @@ -97,13 +97,6 @@ in releaseTools.nixBuild rec { nativeBuildInputs = [ autoreconfHook pkgconfig ]; - patches = [ - (fetchpatch { - url = "https://github.com/NixOS/hydra/pull/648/commits/4171ab4c4fd576c516dc03ba64d1c7945f769af0.patch"; - sha256 = "1fxa2459kdws6qc419dv4084c1ssmys7kqg4ic7n643kybamsgrx"; - }) - ]; - configureFlags = [ "--with-docbook-xsl=${docbook_xsl}/xml/xsl/docbook" ]; NIX_CFLAGS_COMPILE = [ "-pthread" ]; From 7f136b5a5607059c3dca1967ffaca126e3d1fe29 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sat, 14 Sep 2019 01:45:39 +0200 Subject: [PATCH 2/3] nixos/hydra: fix test We ship `https://cache.nixos.org` as binary cache by default which automatically substitutes the test derivation used inside the Hydra test. However it needs to be built locally to confirm that `hydra-queue-runner` works properly. Also inherited the platform name for the test derivation from `system` to ensure that the build can be tested on each supported platform. ZHF #68361 --- nixos/tests/hydra/default.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nixos/tests/hydra/default.nix b/nixos/tests/hydra/default.nix index f99b367ac9b..76000450921 100644 --- a/nixos/tests/hydra/default.nix +++ b/nixos/tests/hydra/default.nix @@ -8,8 +8,10 @@ let trivialJob = pkgs.writeTextDir "trivial.nix" '' { trivial = builtins.derivation { name = "trivial"; - system = "x86_64-linux"; + system = "${system}"; builder = "/bin/sh"; + allowSubstitutes = false; + preferLocalBuild = true; args = ["-c" "echo success > $out; exit 0"]; }; } @@ -57,7 +59,7 @@ let nix = { buildMachines = [{ hostName = "localhost"; - systems = [ "x86_64-linux" ]; + systems = [ system ]; }]; binaryCaches = []; From ce37a040c262aed26e9c6fd63ba527ba1bc028cc Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sat, 14 Sep 2019 12:58:42 +0200 Subject: [PATCH 3/3] 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 --- .../continuous-integration/hydra/default.nix | 20 +++++++++++++++++++ nixos/tests/hydra/create-trivial-project.sh | 2 ++ nixos/tests/hydra/default.nix | 17 +++++++++++----- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/nixos/modules/services/continuous-integration/hydra/default.nix b/nixos/modules/services/continuous-integration/hydra/default.nix index 500acb48562..2da10a9a5e2 100644 --- a/nixos/modules/services/continuous-integration/hydra/default.nix +++ b/nixos/modules/services/continuous-integration/hydra/default.nix @@ -275,6 +275,7 @@ in ${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 @@ -379,6 +380,23 @@ in }; }; + 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 = @@ -416,6 +434,8 @@ in 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 diff --git a/nixos/tests/hydra/create-trivial-project.sh b/nixos/tests/hydra/create-trivial-project.sh index 39122c9b473..5aae2d5bf90 100755 --- a/nixos/tests/hydra/create-trivial-project.sh +++ b/nixos/tests/hydra/create-trivial-project.sh @@ -44,6 +44,8 @@ cat >data.json <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"); @@ -86,6 +91,8 @@ let $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"'); ''; })));