@cryptotaxi247 / infra / commits / 8abfb438

initial hydra module

svn path=/configurations/trunk/tud/; revision=25376

Rob Vermaas committed Jan 4, 2011 at 08:18 UTC 8abfb43838179f9363fb6a7e3b009b510a7d9b84
2 files changed +192 -14
hydra-module.nix new
+186
@@ -0,0 +1,186 @@
1 +{ config, pkgs, ... }:
2 +
3 +with pkgs.lib;
4 +
5 +let
6 + cfg = config.services.hydra;
7 +
8 + hydraConf = pkgs.writeScript "hydra.conf" ''
9 + using_frontend_proxy 1
10 + base_uri ${cfg.hydraURL}
11 + notification_sender ${cfg.notificationSender}
12 + max_servers 25
13 + '';
14 +
15 + env = ''NIX_REMOTE=daemon HYDRA_DBI="${cfg.dbi}" HYDRA_CONFIG=${cfg.baseDir}/data/hydra.conf HYDRA_DATA=${cfg.baseDir}/data'';
16 +in
17 +
18 +{
19 + ###### interface
20 + options = {
21 + services.hydra = rec {
22 +
23 + enable = mkOption {
24 + default = false;
25 + description = ''
26 + Whether to run Hydra services.
27 + '';
28 + };
29 +
30 + baseDir = mkOption {
31 + default = ''/home/${user.default}'';
32 + description = ''
33 + The directory holding configuration, logs and temporary files.
34 + '';
35 + };
36 +
37 + user = mkOption {
38 + default = "hydra";
39 + description = ''
40 + The user the Hydra services should run as.
41 + '';
42 + };
43 +
44 + dbi = mkOption {
45 + default = "dbi:Pg:dbname=hydra;host=webdsl.org;user=hydra;";
46 + description = ''
47 + The DBI string for Hydra database connection
48 + '';
49 + };
50 +
51 + hydraURL = mkOption {
52 + default = "http://hydra.nixos.org";
53 + description = ''
54 + The base URL for the Hydra webserver instance. Used for links in emails.
55 + '';
56 + };
57 +
58 + minimumDiskFree = mkOption {
59 + default = 5;
60 + description = ''
61 + Threshold of minimum disk space (G) to determine if queue runner should run or not.
62 + '';
63 + };
64 +
65 + minimumDiskFreeEvaluator = mkOption {
66 + default = 2;
67 + description = ''
68 + Threshold of minimum disk space (G) to determine if evaluator should run or not.
69 + '';
70 + };
71 +
72 + notificationSender = mkOption {
73 + default = "e.dolstra@tudelft.nl";
74 + description = ''
75 + Sender email address used for email notifications.
76 + '';
77 + };
78 + };
79 +
80 + };
81 +
82 +
83 + ###### implementation
84 +
85 + config = mkIf cfg.enable {
86 +
87 + users.extraUsers = [
88 + { name = cfg.user;
89 + description = "Hydra";
90 + home = cfg.baseDir;
91 + createHome = true;
92 + useDefaultShell = true;
93 + }
94 + ];
95 +
96 + nix.maxJobs = 0;
97 + nix.distributedBuilds = true;
98 + nix.manualNixMachines = true;
99 + nix.useChroot = true;
100 + nix.nrBuildUsers = 100;
101 +
102 + nix.gc.automatic = true;
103 + nix.gc.options = ''--max-freed "$((200 * 1024**3 - 1024 * $(df /nix/store | tail -n 1 | awk '{ print $4 }')))"'';
104 +
105 + nix.extraOptions = ''
106 + gc-keep-outputs = true
107 + gc-keep-derivations = true
108 +
109 + # The default (`true') slows Nix down a lot since the build farm
110 + # has so many GC roots.
111 + gc-check-reachability = false
112 +
113 + # Hydra needs caching of build failures.
114 + build-cache-failure = true
115 +
116 + build-poll-interval = 10
117 +
118 + use-sqlite-wal = false
119 + '';
120 +
121 + jobs.hydra_init =
122 + { description = "hydra-init";
123 + startOn = "started network-interfaces";
124 + preStart = ''
125 + mkdir -p ${cfg.baseDir}/data
126 + chown ${cfg.user} ${cfg.baseDir}/data
127 + ln -sf ${hydraConf} ${cfg.baseDir}/data/hydra.conf
128 + '';
129 + exec = ''
130 + echo done
131 + '';
132 + };
133 +
134 + jobs.hydra_server =
135 + { description = "hydra-server";
136 + startOn = "started network-interfaces hydra-init";
137 + exec = ''
138 + ${pkgs.su}/bin/su - ${cfg.user} -c '${env} hydra_server.pl > ${cfg.baseDir}/data/server.log 2>&1'
139 + '';
140 + };
141 +
142 + jobs.hydra_queue_runner =
143 + { description = "hydra-queue-runner";
144 + startOn = "started network-interfaces hydra-init";
145 + preStart = "${pkgs.su}/bin/su - ${cfg.user} -c 'hydra_queue_runner.pl --unlock'";
146 + exec = ''
147 + ${pkgs.su}/bin/su - ${cfg.user} -c 'nice -n 8 hydra_queue_runner.pl > ${cfg.baseDir}/data/queue_runner.log 2>&1'
148 + '';
149 + };
150 +
151 + jobs.hydra_evaluator =
152 + { description = "hydra-evaluator";
153 + startOn = "started network-interfaces";
154 + exec = ''
155 + ${pkgs.su}/bin/su - ${cfg.user} -c '${env} nice -n 5 hydra_evaluator.pl > ${cfg.baseDir}/data/evaluator.log 2>&1'
156 + '';
157 + };
158 +
159 + services.cron.systemCronJobs =
160 + let
161 + # If there is less than ... GiB of free disk space, stop the queue
162 + # to prevent builds from failing or aborting.
163 + checkSpace = pkgs.writeScript "hydra-check-space"
164 + ''
165 + #! /bin/sh
166 + if [ $(($(stat -f -c '%a' /nix/store) * $(stat -f -c '%S' /nix/store))) -lt $((${toString cfg.minimumDiskFree} * 1024**3)) ]; then
167 + stop hydra-queue-runner
168 + fi
169 + if [ $(($(stat -f -c '%a' /nix/store) * $(stat -f -c '%S' /nix/store))) -lt $((${toString cfg.minimumDiskFreeEvaluator} * 1024**3)) ]; then
170 + stop hydra-evaluator
171 + fi
172 + '';
173 + compressLogs = pkgs.writeScript "compress-logs" ''
174 + #! /bin/sh -e
175 + touch -d 'last month' r
176 + find /nix/var/log/nix/drvs -type f -a ! -newer r -name '*.drv' | xargs bzip2 -v
177 + '';
178 + in
179 + [ "*/5 * * * * root ${checkSpace} &> ${cfg.baseDir}/data/checkspace.log"
180 + "15 5 * * * root ${compressLogs} &> ${cfg.baseDir}/data/compress.log"
181 + "15 02 * * * ${cfg.user} ${env} hydra_update_gc_roots.pl &> ${cfg.baseDir}/data/gc-roots.log"
182 + ];
183 +
184 + };
185 +}
186 +
lucifer.nix
+6 -14
@@ -1,7 +1,7 @@
1 { config, pkgs, ... }:
2
3 {
4 - require = [ ./common.nix ];
4 + require = [ ./common.nix ./hydra-module.nix ];
5
6 nixpkgs.system = "x86_64-linux";
7
@@ -14,6 +14,8 @@
14 boot.initrd.kernelModules = [ "uhci_hcd" "ehci_hcd" "ata_piix" "megaraid_sas" "usbhid" ];
15 boot.kernelModules = [ "acpi-cpufreq" "kvm-intel" ];
16
17 + services.hydra.enable = true;
18 +
19 fileSystems =
20 [ { mountPoint = "/";
21 label = "nixos";
@@ -41,17 +43,10 @@
43
44 nixpkgs.config.subversion.pythonBindings = true;
45
44 - #services.hydraChannelMirror.enable = true;
46 + services.hydraChannelMirror.enable = true;
47 + services.hydraChannelMirror.enableBinaryPatches = true;
48 services.hydraChannelMirror.period = "0-59/15 * * * *";
46 -
47 - services.cron.systemCronJobs =
48 - [ "0-59/15 * * * * hydra-mirror ENABLE_PATCHES=1 perl -I/home/hydra-mirror/nix/inst/libexec/nix ~/release/channels/mirror-channel.pl http://hydra.nixos.org/jobset/nixpkgs/trunk/channel/latest /data/releases/nixpkgs/channels/nixpkgs-unstable /data/releases/nars http://nixos.org/releases/nars /data/releases/patches http://nixos.org/releases/patches http://hydra.nixos.org/job/nixpkgs/trunk/tarball/latest/download-by-type/file/source-dist >> /var/log/nixpkgs-unstable.log 2>&1"
49 - ];
50 -
51 - /*
52 - services.httpd.enable = true;
53 - services.httpd.adminAddr = "rob.vermaas@gmail.com";
54 - */
49 + services.hydraChannelMirror.dataDir = "/data/releases";
50
51 services.postgresql = {
52 enable = true;
@@ -67,9 +62,6 @@
62 '';
63 };
64
70 - nix.gc.automatic = true;
71 - nix.gc.options = "--max-freed $((100 * 1024**3))";
72 -
65 services.tomcat = {
66 enable = true;
67 baseDir = "/data/tomcat";