2011-05-05 06:27:38 +00:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.hydra;
|
|
|
|
|
2013-03-22 16:16:05 +00:00
|
|
|
baseDir = "/var/lib/hydra";
|
|
|
|
|
2013-09-22 23:20:09 +00:00
|
|
|
hydraConf = pkgs.writeScript "hydra.conf" cfg.extraConfig;
|
2013-01-22 13:41:02 +00:00
|
|
|
|
2013-11-06 16:32:50 +00:00
|
|
|
hydraEnv =
|
|
|
|
{ HYDRA_DBI = cfg.dbi;
|
2013-03-22 16:16:05 +00:00
|
|
|
HYDRA_CONFIG = "${baseDir}/data/hydra.conf";
|
|
|
|
HYDRA_DATA = "${baseDir}/data";
|
2013-11-06 16:32:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
env =
|
|
|
|
{ NIX_REMOTE = "daemon";
|
2013-03-22 12:58:08 +00:00
|
|
|
OPENSSL_X509_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt";
|
2013-03-22 17:22:33 +00:00
|
|
|
GIT_SSL_CAINFO = "/etc/ssl/certs/ca-bundle.crt";
|
2013-11-06 16:32:50 +00:00
|
|
|
} // hydraEnv;
|
2013-11-06 15:17:11 +00:00
|
|
|
|
2013-03-22 12:58:08 +00:00
|
|
|
serverEnv = env //
|
2013-11-06 16:27:36 +00:00
|
|
|
{ HYDRA_TRACKER = cfg.tracker;
|
2013-07-28 16:16:46 +00:00
|
|
|
} // (optionalAttrs cfg.debugServer { DBIC_TRACE = 1; });
|
2011-05-05 06:27:38 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
options = {
|
2013-11-06 16:27:36 +00:00
|
|
|
|
2011-05-05 06:27:38 +00:00
|
|
|
services.hydra = rec {
|
2013-01-22 13:41:02 +00:00
|
|
|
|
2011-05-05 06:27:38 +00:00
|
|
|
enable = mkOption {
|
2013-11-06 15:34:16 +00:00
|
|
|
type = types.bool;
|
2011-05-05 06:27:38 +00:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to run Hydra services.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
dbi = mkOption {
|
2013-11-06 15:34:16 +00:00
|
|
|
type = types.string;
|
2013-11-06 16:07:25 +00:00
|
|
|
default = "dbi:Pg:dbname=hydra;user=hydra;";
|
|
|
|
example = "dbi:Pg:dbname=hydra;host=postgres.example.org;user=foo;";
|
2011-05-05 06:27:38 +00:00
|
|
|
description = ''
|
2011-05-05 10:07:59 +00:00
|
|
|
The DBI string for Hydra database connection.
|
2011-05-05 06:27:38 +00:00
|
|
|
'';
|
|
|
|
};
|
2013-01-22 13:41:02 +00:00
|
|
|
|
2013-11-06 15:34:16 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.path;
|
2013-03-22 12:58:08 +00:00
|
|
|
#default = pkgs.hydra;
|
2013-11-06 15:34:16 +00:00
|
|
|
description = "The Hydra package.";
|
2011-05-05 06:27:38 +00:00
|
|
|
};
|
2013-01-22 13:41:02 +00:00
|
|
|
|
2011-05-05 06:27:38 +00:00
|
|
|
hydraURL = mkOption {
|
2013-11-06 15:34:16 +00:00
|
|
|
type = types.str;
|
2011-05-05 06:27:38 +00:00
|
|
|
description = ''
|
2013-01-22 13:41:02 +00:00
|
|
|
The base URL for the Hydra webserver instance. Used for links in emails.
|
2011-05-05 06:27:38 +00:00
|
|
|
'';
|
|
|
|
};
|
2011-05-05 10:07:56 +00:00
|
|
|
|
2013-08-28 22:20:51 +00:00
|
|
|
listenHost = mkOption {
|
2013-11-06 15:34:16 +00:00
|
|
|
type = types.str;
|
2013-08-28 22:20:51 +00:00
|
|
|
default = "*";
|
|
|
|
example = "localhost";
|
|
|
|
description = ''
|
|
|
|
The hostname or address to listen on or <literal>*</literal> to listen
|
|
|
|
on all interfaces.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2011-05-05 10:07:56 +00:00
|
|
|
port = mkOption {
|
2013-11-06 15:34:16 +00:00
|
|
|
type = types.int;
|
2011-05-05 10:07:56 +00:00
|
|
|
default = 3000;
|
|
|
|
description = ''
|
|
|
|
TCP port the web server should listen to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2011-05-05 06:27:38 +00:00
|
|
|
minimumDiskFree = mkOption {
|
2013-11-06 15:34:16 +00:00
|
|
|
type = types.int;
|
2011-05-05 06:27:38 +00:00
|
|
|
default = 5;
|
|
|
|
description = ''
|
2013-11-06 15:34:16 +00:00
|
|
|
Threshold of minimum disk space (GiB) to determine if queue runner should run or not.
|
2011-05-05 06:27:38 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
minimumDiskFreeEvaluator = mkOption {
|
2013-11-06 15:34:16 +00:00
|
|
|
type = types.int;
|
2011-05-05 06:27:38 +00:00
|
|
|
default = 2;
|
|
|
|
description = ''
|
2013-11-06 15:34:16 +00:00
|
|
|
Threshold of minimum disk space (GiB) to determine if evaluator should run or not.
|
2011-05-05 06:27:38 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
notificationSender = mkOption {
|
2013-11-06 15:34:16 +00:00
|
|
|
type = types.str;
|
2011-05-05 06:27:38 +00:00
|
|
|
description = ''
|
2013-01-22 13:41:02 +00:00
|
|
|
Sender email address used for email notifications.
|
2011-05-05 06:27:38 +00:00
|
|
|
'';
|
2013-01-22 13:41:02 +00:00
|
|
|
};
|
2011-05-05 06:27:38 +00:00
|
|
|
|
|
|
|
tracker = mkOption {
|
2013-11-06 15:34:16 +00:00
|
|
|
type = types.str;
|
2011-05-05 06:27:38 +00:00
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Piece of HTML that is included on all pages.
|
|
|
|
'';
|
2011-05-05 10:07:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
logo = mkOption {
|
2013-11-06 16:27:36 +00:00
|
|
|
type = types.nullOr types.path;
|
2011-05-05 10:07:59 +00:00
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
File name of an alternate logo to be displayed on the web pages.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-07-28 15:11:09 +00:00
|
|
|
debugServer = mkOption {
|
|
|
|
type = types.bool;
|
2013-11-06 15:34:16 +00:00
|
|
|
default = false;
|
2013-07-28 15:11:09 +00:00
|
|
|
description = "Whether to run the server in debug mode";
|
|
|
|
};
|
|
|
|
|
2013-09-22 23:20:09 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
description = "Extra lines for the hydra config";
|
|
|
|
};
|
|
|
|
|
2011-05-05 06:27:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
2013-01-22 13:41:02 +00:00
|
|
|
|
2011-05-05 06:27:38 +00:00
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2013-11-06 16:27:36 +00:00
|
|
|
|
2013-09-22 23:20:09 +00:00
|
|
|
services.hydra.extraConfig =
|
|
|
|
''
|
|
|
|
using_frontend_proxy 1
|
|
|
|
base_uri ${cfg.hydraURL}
|
|
|
|
notification_sender ${cfg.notificationSender}
|
|
|
|
max_servers 25
|
2013-11-06 16:27:36 +00:00
|
|
|
${optionalString (cfg.logo != null) ''
|
|
|
|
hydra_logo ${cfg.logo}
|
|
|
|
''}
|
2013-09-22 23:20:09 +00:00
|
|
|
'';
|
|
|
|
|
2013-11-06 15:34:16 +00:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2011-05-05 06:27:38 +00:00
|
|
|
|
2013-11-06 16:32:50 +00:00
|
|
|
environment.variables = hydraEnv;
|
|
|
|
|
2013-03-22 16:16:05 +00:00
|
|
|
users.extraUsers.hydra =
|
|
|
|
{ description = "Hydra";
|
2013-03-22 17:22:00 +00:00
|
|
|
home = baseDir;
|
2011-05-05 06:27:38 +00:00
|
|
|
createHome = true;
|
|
|
|
useDefaultShell = true;
|
2013-03-22 17:22:00 +00:00
|
|
|
};
|
2011-05-05 06:27:38 +00:00
|
|
|
|
|
|
|
nix.extraOptions = ''
|
|
|
|
gc-keep-outputs = true
|
|
|
|
gc-keep-derivations = true
|
|
|
|
|
|
|
|
# The default (`true') slows Nix down a lot since the build farm
|
|
|
|
# has so many GC roots.
|
|
|
|
gc-check-reachability = false
|
|
|
|
|
|
|
|
# Hydra needs caching of build failures.
|
|
|
|
build-cache-failure = true
|
|
|
|
|
|
|
|
build-poll-interval = 10
|
2013-11-06 15:17:11 +00:00
|
|
|
|
2013-03-22 12:58:08 +00:00
|
|
|
# Online log compression makes it impossible to get the tail of
|
|
|
|
# builds that are in progress.
|
|
|
|
build-compress-log = false
|
2011-05-05 06:27:38 +00:00
|
|
|
'';
|
|
|
|
|
2013-03-22 17:22:00 +00:00
|
|
|
systemd.services."hydra-init" =
|
2013-03-22 12:58:08 +00:00
|
|
|
{ wantedBy = [ "multi-user.target" ];
|
2013-07-28 15:05:03 +00:00
|
|
|
requires = [ "postgresql.service" ];
|
|
|
|
after = [ "postgresql.service" ];
|
2013-03-22 17:22:00 +00:00
|
|
|
environment = env;
|
2014-04-10 18:09:29 +00:00
|
|
|
preStart = ''
|
2013-11-06 16:29:34 +00:00
|
|
|
mkdir -m 0700 -p ${baseDir}/data
|
2013-03-22 17:22:00 +00:00
|
|
|
chown hydra ${baseDir}/data
|
|
|
|
ln -sf ${hydraConf} ${baseDir}/data/hydra.conf
|
2013-11-06 16:07:25 +00:00
|
|
|
${optionalString (cfg.dbi == "dbi:Pg:dbname=hydra;user=hydra;") ''
|
|
|
|
if ! [ -e ${baseDir}/.db-created ]; then
|
|
|
|
${config.services.postgresql.package}/bin/createuser hydra
|
2013-07-28 15:05:03 +00:00
|
|
|
${config.services.postgresql.package}/bin/createdb -O hydra hydra
|
2013-11-06 16:07:25 +00:00
|
|
|
touch ${baseDir}/.db-created
|
|
|
|
fi
|
|
|
|
''}
|
2011-05-05 06:27:38 +00:00
|
|
|
'';
|
2014-04-10 18:09:29 +00:00
|
|
|
serviceConfig.ExecStart = "${cfg.package}/bin/hydra-init";
|
2014-04-10 22:06:31 +00:00
|
|
|
serviceConfig.PermissionsStartOnly = true;
|
2014-04-10 18:09:29 +00:00
|
|
|
serviceConfig.User = "hydra";
|
2013-03-22 17:22:00 +00:00
|
|
|
serviceConfig.Type = "oneshot";
|
2013-07-28 15:05:03 +00:00
|
|
|
serviceConfig.RemainAfterExit = true;
|
2013-03-22 12:58:08 +00:00
|
|
|
};
|
2013-11-06 15:17:11 +00:00
|
|
|
|
2013-03-22 12:58:08 +00:00
|
|
|
systemd.services."hydra-server" =
|
|
|
|
{ wantedBy = [ "multi-user.target" ];
|
2013-11-06 16:09:24 +00:00
|
|
|
requires = [ "hydra-init.service" ];
|
2013-03-22 12:58:08 +00:00
|
|
|
after = [ "hydra-init.service" ];
|
|
|
|
environment = serverEnv;
|
|
|
|
serviceConfig =
|
2013-11-06 16:19:57 +00:00
|
|
|
{ ExecStart =
|
|
|
|
"@${cfg.package}/bin/hydra-server hydra-server -f -h '${cfg.listenHost}' "
|
|
|
|
+ "-p ${toString cfg.port} --max_spare_servers 5 --max_servers 25 "
|
|
|
|
+ "--max_requests 100 ${optionalString cfg.debugServer "-d"}";
|
2013-03-22 16:16:05 +00:00
|
|
|
User = "hydra";
|
2013-03-22 12:58:08 +00:00
|
|
|
Restart = "always";
|
|
|
|
};
|
2011-05-05 06:27:38 +00:00
|
|
|
};
|
|
|
|
|
2013-03-22 12:58:08 +00:00
|
|
|
systemd.services."hydra-queue-runner" =
|
|
|
|
{ wantedBy = [ "multi-user.target" ];
|
2013-11-06 16:09:24 +00:00
|
|
|
requires = [ "hydra-init.service" ];
|
2013-03-22 12:58:08 +00:00
|
|
|
after = [ "hydra-init.service" "network.target" ];
|
2013-07-28 15:06:02 +00:00
|
|
|
path = [ pkgs.nettools ];
|
2013-03-22 12:58:08 +00:00
|
|
|
environment = env;
|
|
|
|
serviceConfig =
|
2013-11-06 15:34:16 +00:00
|
|
|
{ ExecStartPre = "${cfg.package}/bin/hydra-queue-runner --unlock";
|
|
|
|
ExecStart = "@${cfg.package}/bin/hydra-queue-runner hydra-queue-runner";
|
2013-03-22 16:16:05 +00:00
|
|
|
User = "hydra";
|
2013-03-22 12:58:08 +00:00
|
|
|
Restart = "always";
|
|
|
|
};
|
2011-05-05 06:27:38 +00:00
|
|
|
};
|
|
|
|
|
2013-03-22 12:58:08 +00:00
|
|
|
systemd.services."hydra-evaluator" =
|
|
|
|
{ wantedBy = [ "multi-user.target" ];
|
2013-11-06 16:09:24 +00:00
|
|
|
requires = [ "hydra-init.service" ];
|
2013-03-22 12:58:08 +00:00
|
|
|
after = [ "hydra-init.service" "network.target" ];
|
2013-07-28 15:06:02 +00:00
|
|
|
path = [ pkgs.nettools ];
|
2013-03-22 12:58:08 +00:00
|
|
|
environment = env;
|
|
|
|
serviceConfig =
|
2013-11-06 15:34:16 +00:00
|
|
|
{ ExecStart = "@${cfg.package}/bin/hydra-evaluator hydra-evaluator";
|
2013-03-22 16:16:05 +00:00
|
|
|
User = "hydra";
|
2013-03-22 12:58:08 +00:00
|
|
|
Restart = "always";
|
|
|
|
};
|
2011-05-05 06:27:38 +00:00
|
|
|
};
|
|
|
|
|
2013-03-22 12:58:08 +00:00
|
|
|
systemd.services."hydra-update-gc-roots" =
|
2013-11-06 16:09:24 +00:00
|
|
|
{ requires = [ "hydra-init.service" ];
|
2013-03-22 12:58:08 +00:00
|
|
|
after = [ "hydra-init.service" ];
|
|
|
|
environment = env;
|
|
|
|
serviceConfig =
|
2013-11-06 15:34:16 +00:00
|
|
|
{ ExecStart = "@${cfg.package}/bin/hydra-update-gc-roots hydra-update-gc-roots";
|
2013-03-22 16:16:05 +00:00
|
|
|
User = "hydra";
|
2013-03-22 12:58:08 +00:00
|
|
|
};
|
2013-11-06 16:29:22 +00:00
|
|
|
startAt = "02:15";
|
2011-05-05 06:27:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
services.cron.systemCronJobs =
|
2012-06-14 08:57:12 +00:00
|
|
|
let
|
|
|
|
# If there is less than ... GiB of free disk space, stop the queue
|
|
|
|
# to prevent builds from failing or aborting.
|
|
|
|
checkSpace = pkgs.writeScript "hydra-check-space"
|
|
|
|
''
|
2013-03-22 16:16:05 +00:00
|
|
|
#! ${pkgs.stdenv.shell}
|
2012-06-14 08:57:12 +00:00
|
|
|
if [ $(($(stat -f -c '%a' /nix/store) * $(stat -f -c '%S' /nix/store))) -lt $((${toString cfg.minimumDiskFree} * 1024**3)) ]; then
|
2013-04-11 08:44:45 +00:00
|
|
|
systemctl stop hydra-queue-runner
|
2013-03-22 12:58:08 +00:00
|
|
|
fi
|
|
|
|
if [ $(($(stat -f -c '%a' /nix/store) * $(stat -f -c '%S' /nix/store))) -lt $((${toString cfg.minimumDiskFreeEvaluator} * 1024**3)) ]; then
|
2013-04-11 08:44:45 +00:00
|
|
|
systemctl stop hydra-evaluator
|
2012-06-14 08:57:12 +00:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
compressLogs = pkgs.writeScript "compress-logs" ''
|
2013-11-04 08:56:33 +00:00
|
|
|
#! ${pkgs.stdenv.shell} -e
|
|
|
|
find /nix/var/log/nix/drvs \
|
|
|
|
-type f -a ! -newermt 'last month' \
|
|
|
|
-name '*.drv' -exec bzip2 -v {} +
|
2012-06-14 08:57:12 +00:00
|
|
|
'';
|
|
|
|
in
|
2013-03-22 17:22:00 +00:00
|
|
|
[ "*/5 * * * * root ${checkSpace} &> ${baseDir}/data/checkspace.log"
|
|
|
|
"15 5 * * * root ${compressLogs} &> ${baseDir}/data/compress.log"
|
2012-06-14 08:57:12 +00:00
|
|
|
];
|
|
|
|
};
|
2011-05-05 06:27:38 +00:00
|
|
|
}
|