hydra-module.nix: Cleanup

Remove some unnecessary configurability, remove all hydra.nixos.org
assumptions, remove some policy (e.g. nix.gc.automatic) that are
orthogonal to hydra.

Signed-off-by: Shea Levy <shea@shealevy.com>
This commit is contained in:
Shea Levy 2013-03-22 12:16:05 -04:00
parent d8e2dfc0ed
commit e4a8818bae

View file

@ -5,6 +5,8 @@ with pkgs.lib;
let let
cfg = config.services.hydra; cfg = config.services.hydra;
baseDir = "/var/lib/hydra";
hydraConf = pkgs.writeScript "hydra.conf" hydraConf = pkgs.writeScript "hydra.conf"
'' ''
using_frontend_proxy 1 using_frontend_proxy 1
@ -16,8 +18,8 @@ let
env = env =
{ NIX_REMOTE = "daemon"; { NIX_REMOTE = "daemon";
HYDRA_DBI = cfg.dbi; HYDRA_DBI = cfg.dbi;
HYDRA_CONFIG = "${cfg.baseDir}/data/hydra.conf"; HYDRA_CONFIG = "${baseDir}/data/hydra.conf";
HYDRA_DATA = "${cfg.baseDir}/data"; HYDRA_DATA = "${baseDir}/data";
HYDRA_PORT = "${toString cfg.port}"; HYDRA_PORT = "${toString cfg.port}";
OPENSSL_X509_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt"; OPENSSL_X509_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt";
}; };
@ -40,22 +42,8 @@ in
''; '';
}; };
baseDir = mkOption {
default = "/home/${user.default}";
description = ''
The directory holding configuration, logs and temporary files.
'';
};
user = mkOption {
default = "hydra";
description = ''
The user the Hydra services should run as.
'';
};
dbi = mkOption { dbi = mkOption {
default = "dbi:Pg:dbname=hydra;host=localhost;user=root;"; default = "dbi:Pg:dbname=hydra;host=localhost;user=hydra;";
example = "dbi:SQLite:/home/hydra/db/hydra.sqlite"; example = "dbi:SQLite:/home/hydra/db/hydra.sqlite";
description = '' description = ''
The DBI string for Hydra database connection. The DBI string for Hydra database connection.
@ -70,7 +58,6 @@ in
}; };
hydraURL = mkOption { hydraURL = mkOption {
default = "http://hydra.nixos.org";
description = '' description = ''
The base URL for the Hydra webserver instance. Used for links in emails. The base URL for the Hydra webserver instance. Used for links in emails.
''; '';
@ -98,7 +85,6 @@ in
}; };
notificationSender = mkOption { notificationSender = mkOption {
default = "e.dolstra@tudelft.nl";
description = '' description = ''
Sender email address used for email notifications. Sender email address used for email notifications.
''; '';
@ -118,13 +104,6 @@ in
''; '';
}; };
autoStart = mkOption {
default = true;
description = ''
If hydra upstart jobs should start automatically.
'';
};
useWAL = mkOption { useWAL = mkOption {
default = true; default = true;
description = '' description = ''
@ -142,18 +121,14 @@ in
config = mkIf cfg.enable { config = mkIf cfg.enable {
environment.systemPackages = [ cfg.hydra ]; environment.systemPackages = [ cfg.hydra ];
users.extraUsers = [ users.extraUsers.hydra =
{ name = cfg.user; { description = "Hydra";
description = "Hydra";
home = cfg.baseDir; home = cfg.baseDir;
createHome = true; createHome = true;
useDefaultShell = true; useDefaultShell = true;
} }
]; ];
# We have our own crontab entries for GC, see below.
nix.gc.automatic = false;
nix.extraOptions = '' nix.extraOptions = ''
gc-keep-outputs = true gc-keep-outputs = true
gc-keep-derivations = true gc-keep-derivations = true
@ -177,8 +152,8 @@ in
jobs."hydra-init" = jobs."hydra-init" =
{ wantedBy = [ "multi-user.target" ]; { wantedBy = [ "multi-user.target" ];
script = '' script = ''
mkdir -p ${cfg.baseDir}/data mkdir -p ${baseDir}/data
chown ${cfg.user} ${cfg.baseDir}/data chown hydra ${cfg.baseDir}/data
ln -sf ${hydraConf} ${cfg.baseDir}/data/hydra.conf ln -sf ${hydraConf} ${cfg.baseDir}/data/hydra.conf
''; '';
task = true; task = true;
@ -191,7 +166,7 @@ in
environment = serverEnv; environment = serverEnv;
serviceConfig = serviceConfig =
{ ExecStart = "@${cfg.hydra}/bin/hydra-server hydra-server -f -h \* --max_spare_servers 5 --max_servers 25 --max_requests 100"; { ExecStart = "@${cfg.hydra}/bin/hydra-server hydra-server -f -h \* --max_spare_servers 5 --max_servers 25 --max_requests 100";
User = cfg.user; User = "hydra";
Restart = "always"; Restart = "always";
}; };
}; };
@ -205,7 +180,7 @@ in
serviceConfig = serviceConfig =
{ ExecStartPre = "${cfg.hydra}/bin/hydra-queue-runner --unlock"; { ExecStartPre = "${cfg.hydra}/bin/hydra-queue-runner --unlock";
ExecStart = "@${cfg.hydra}/bin/hydra-queue-runner hydra-queue-runner"; ExecStart = "@${cfg.hydra}/bin/hydra-queue-runner hydra-queue-runner";
User = cfg.user; User = "hydra";
Restart = "always"; Restart = "always";
}; };
}; };
@ -218,7 +193,7 @@ in
environment = env; environment = env;
serviceConfig = serviceConfig =
{ ExecStart = "@${cfg.hydra}/bin/hydra-evaluator hydra-evaluator"; { ExecStart = "@${cfg.hydra}/bin/hydra-evaluator hydra-evaluator";
User = cfg.user; User = "hydra";
Restart = "always"; Restart = "always";
}; };
}; };
@ -229,7 +204,7 @@ in
environment = env; environment = env;
serviceConfig = serviceConfig =
{ ExecStart = "@${cfg.hydra}/bin/hydra-update-gc-roots hydra-update-gc-roots"; { ExecStart = "@${cfg.hydra}/bin/hydra-update-gc-roots hydra-update-gc-roots";
User = cfg.user; User = "hydra";
}; };
}; };
@ -239,7 +214,7 @@ in
# to prevent builds from failing or aborting. # to prevent builds from failing or aborting.
checkSpace = pkgs.writeScript "hydra-check-space" checkSpace = pkgs.writeScript "hydra-check-space"
'' ''
#! /bin/sh #! ${pkgs.stdenv.shell}
if [ $(($(stat -f -c '%a' /nix/store) * $(stat -f -c '%S' /nix/store))) -lt $((${toString cfg.minimumDiskFree} * 1024**3)) ]; then if [ $(($(stat -f -c '%a' /nix/store) * $(stat -f -c '%S' /nix/store))) -lt $((${toString cfg.minimumDiskFree} * 1024**3)) ]; then
stop hydra_queue_runner stop hydra_queue_runner
fi fi
@ -249,7 +224,7 @@ in
''; '';
compressLogs = pkgs.writeScript "compress-logs" '' compressLogs = pkgs.writeScript "compress-logs" ''
#! /bin/sh -e #! ${pkgs.stdenv.shell} -e
touch -d 'last month' r touch -d 'last month' r
find /nix/var/log/nix/drvs -type f -a ! -newer r -name '*.drv' | xargs bzip2 -v find /nix/var/log/nix/drvs -type f -a ! -newer r -name '*.drv' | xargs bzip2 -v
''; '';