@cryptotaxi247 / infra-1 / commits / 46648c6e

Use upstream Hydra module

Eelco Dolstra committed Jul 6, 2015 at 13:49 UTC 46648c6e45556b6e7940a3b2d7630c6399e184fa
2 files changed +36 -250
delft/hydra.nix deleted
-241
@@ -1,241 +0,0 @@
1 -{ config, pkgs, ... }:
2 -
3 -with pkgs.lib;
4 -
5 -let
6 -
7 - cfg = config.services.hydra;
8 -
9 - hydra = "/nix/var/nix/profiles/per-user/hydra/profile"; # FIXME
10 -
11 - hydraConf = pkgs.writeScript "hydra.conf"
12 - ''
13 - using_frontend_proxy 1
14 - base_uri ${cfg.hydraURL}
15 - notification_sender ${cfg.notificationSender}
16 - max_servers 50
17 - enable_persona 1
18 -
19 - binary_cache_secret_key_file = /home/hydra-server/.keys/hydra.nixos.org-1/secret
20 -
21 - <hipchat>
22 - jobs = (hydra|nixops):.*:.*
23 - room = 182482
24 - token = ${builtins.readFile ./hipchat-lb-token}
25 - </hipchat>
26 - '';
27 -
28 - env =
29 - { NIX_REMOTE = "daemon";
30 - NIX_CONF_DIR = "/etc/nix";
31 - HYDRA_DBI = cfg.dbi;
32 - HYDRA_CONFIG = hydraConf;
33 - HYDRA_DATA = cfg.baseDir;
34 - SSL_CERT_FILE = "/etc/ssl/certs/ca-certificates.crt";
35 - };
36 -
37 - serverEnv = env //
38 - { HYDRA_LOGO = cfg.logo;
39 - HYDRA_SERVER_DATA = "/var/lib/hydra-server";
40 - COLUMNS = "80";
41 - };
42 -
43 -in
44 -
45 -{
46 - ###### interface
47 -
48 - options = {
49 -
50 - services.hydra = rec {
51 -
52 - enable = mkOption {
53 - default = false;
54 - description = ''
55 - Whether to run Hydra services.
56 - '';
57 - };
58 -
59 - baseDir = mkOption {
60 - default = "/var/lib/hydra";
61 - description = ''
62 - The directory holding configuration, logs and temporary files.
63 - '';
64 - };
65 -
66 - dbi = mkOption {
67 - default = "dbi:Pg:dbname=hydra;host=wendy;user=hydra;";
68 - description = ''
69 - The DBI string for Hydra database connection
70 - '';
71 - };
72 -
73 - hydraURL = mkOption {
74 - default = "http://hydra.nixos.org";
75 - description = ''
76 - The base URL for the Hydra webserver instance. Used for links in emails.
77 - '';
78 - };
79 -
80 - minimumDiskFree = mkOption {
81 - default = 5;
82 - description = ''
83 - Threshold of minimum disk space (GiB) to determine if queue runner should run or not.
84 - '';
85 - };
86 -
87 - minimumDiskFreeEvaluator = mkOption {
88 - default = 2;
89 - description = ''
90 - Threshold of minimum disk space (GiB) to determine if evaluator should run or not.
91 - '';
92 - };
93 -
94 - notificationSender = mkOption {
95 - default = "e.dolstra@tudelft.nl";
96 - description = ''
97 - Sender email address used for email notifications.
98 - '';
99 - };
100 -
101 - logo = mkOption {
102 - default = "";
103 - description = ''
104 - Path to a file containing the logo of your Hydra instance.
105 - '';
106 - };
107 -
108 - };
109 -
110 - };
111 -
112 -
113 - ###### implementation
114 -
115 - config = mkIf cfg.enable {
116 -
117 - users.extraUsers.hydra =
118 - { description = "Hydra";
119 - group = "hydra";
120 - createHome = true;
121 - home = "/home/hydra";
122 - useDefaultShell = true;
123 - };
124 -
125 - users.extraUsers.hydra-server =
126 - { description = "Hydra Web Server";
127 - group = "hydra";
128 - createHome = true;
129 - home = "/home/hydra-server";
130 - useDefaultShell = true;
131 - };
132 -
133 - users.extraGroups.hydra = { };
134 -
135 - nix.maxJobs = 0;
136 - nix.distributedBuilds = true;
137 -
138 - nix.gc.automatic = true;
139 - nix.gc.options = ''--max-freed "$((700 * 1024**3 - 1024 * $(df -P -k /nix/store | tail -n 1 | ${pkgs.gawk}/bin/awk '{ print $4 }')))"'';
140 -
141 - nix.extraOptions = ''
142 - gc-keep-outputs = true
143 - gc-keep-derivations = true
144 -
145 - # The default (`true') slows Nix down a lot since the build farm
146 - # has so many GC roots.
147 - gc-check-reachability = false
148 -
149 - # Hydra needs caching of build failures.
150 - build-cache-failure = true
151 -
152 - build-poll-interval = 10
153 -
154 - # Online log compression makes it impossible to get the tail of
155 - # builds that are in progress.
156 - build-compress-log = false
157 - '';
158 -
159 - jobs.hydra-init =
160 - { wantedBy = [ "multi-user.target" ];
161 - script = ''
162 - mkdir -m 0750 -p ${cfg.baseDir}
163 - chown hydra.hydra ${cfg.baseDir}
164 - '';
165 - task = true;
166 - };
167 -
168 - systemd.services.hydra-server =
169 - { wantedBy = [ "multi-user.target" ];
170 - wants = [ "hydra-init.service" ];
171 - after = [ "hydra-init.service" ];
172 - environment = serverEnv;
173 - preStart =
174 - ''
175 - mkdir -m 0700 -p /var/lib/hydra-server
176 - chown hydra-server.hydra /var/lib/hydra-server
177 - '';
178 - serviceConfig =
179 - { ExecStart = "@${hydra}/bin/hydra-server hydra-server -f -h \* --max_spare_servers 5 --max_servers 25 --max_requests 100";
180 - User = "hydra-server";
181 - PermissionsStartOnly = true;
182 - Restart = "always";
183 - };
184 - };
185 -
186 - systemd.services.hydra-queue-runner =
187 - { #wantedBy = [ "multi-user.target" ];
188 - wants = [ "hydra-init.service" ];
189 - after = [ "hydra-init.service" "network.target" ];
190 - path = [ pkgs.nettools pkgs.ssmtp ];
191 - environment = env;
192 - serviceConfig =
193 - { ExecStartPre = "${hydra}/bin/hydra-queue-runner --unlock";
194 - ExecStart = "@${hydra}/bin/hydra-queue-runner hydra-queue-runner";
195 - ExecStopPost = "${hydra}/bin/hydra-queue-runner --unlock";
196 - User = "hydra";
197 - Restart = "always";
198 - };
199 - };
200 -
201 - systemd.services.hydra-evaluator =
202 - { wantedBy = [ "multi-user.target" ];
203 - wants = [ "hydra-init.service" ];
204 - after = [ "hydra-init.service" "network.target" ];
205 - path = [ pkgs.nettools pkgs.ssmtp ];
206 - environment = env;
207 - serviceConfig =
208 - { ExecStart = "@${hydra}/bin/hydra-evaluator hydra-evaluator";
209 - User = "hydra";
210 - Restart = "always";
211 - };
212 - };
213 -
214 - systemd.services.hydra-update-gc-roots =
215 - { wants = [ "hydra-init.service" ];
216 - after = [ "hydra-init.service" ];
217 - environment = env;
218 - serviceConfig =
219 - { ExecStart = "@${hydra}/bin/hydra-update-gc-roots hydra-update-gc-roots";
220 - User = "hydra";
221 - };
222 - startAt = "2,14:15";
223 - };
224 -
225 - # If there is less than ... GiB of free disk space, stop the queue
226 - # to prevent builds from failing or aborting.
227 - systemd.services.hydra-check-space =
228 - { script =
229 - ''
230 - if [ $(($(stat -f -c '%a' /nix/store) * $(stat -f -c '%S' /nix/store))) -lt $((${toString cfg.minimumDiskFree} * 1024**3)) ]; then
231 - systemctl stop hydra-queue-runner
232 - fi
233 - if [ $(($(stat -f -c '%a' /nix/store) * $(stat -f -c '%S' /nix/store))) -lt $((${toString cfg.minimumDiskFreeEvaluator} * 1024**3)) ]; then
234 - systemctl stop hydra-evaluator
235 - fi
236 - '';
237 - startAt = "*:0/5";
238 - };
239 -
240 - };
241 -}
delft/lucifer.nix
+36 -9
@@ -1,9 +1,11 @@
1 -{ config, pkgs, ... }:
1 +{ config, lib, pkgs, ... }:
2 +
3 +with lib;
4
5 {
4 - require =
6 + imports =
7 [ ./common.nix
6 - ./hydra.nix
8 + ../../hydra/hydra-module.nix
9 ./hydra-mirror.nix
10 ./megacli.nix
11 ./datadog.nix
@@ -29,9 +31,6 @@
31 boot.kernelModules = [ "acpi-cpufreq" "kvm-intel" ];
32 boot.extraModulePackages = [config.boot.kernelPackages.sysdig];
33
32 - services.hydra.enable = true;
33 - services.hydra.logo = ./hydra-logo.png;
34 -
34 fileSystems."/".device = "/dev/disk/by-label/nixos";
35
36 fileSystems."/fatdata" =
@@ -91,11 +90,11 @@
90 systemd.services.nix-daemon.serviceConfig.CPUShares = 200;
91 systemd.services.nix-daemon.serviceConfig.BlockIOWeight = 500;
92 systemd.services.hydra-queue-runner.serviceConfig.CPUShares = 200;
94 - systemd.services.hydra-queue-runner.serviceConfig.BlockIOWeight = 200;
93 + systemd.services.hydra-queue-runner.serviceConfig.BlockIOWeight = 700;
94 systemd.services.hydra-evaluator.serviceConfig.CPUShares = 100;
95 systemd.services.hydra-evaluator.serviceConfig.BlockIOWeight = 100;
96 systemd.services.hydra-server.serviceConfig.CPUShares = 700;
98 - systemd.services.hydra-server.serviceConfig.BlockIOWeight = 700;
97 + systemd.services.hydra-server.serviceConfig.BlockIOWeight = 200;
98
99 nix.sshServe.enable = true;
100 nix.sshServe.keys = with import ../ssh-keys.nix; [ eelco rob ];
@@ -110,7 +109,8 @@
109 };
110
111 users.extraUsers.hydra.openssh.authorizedKeys.keys = with import ../ssh-keys.nix; [ eelco rob ];
113 - users.extraUsers.hydra-server.openssh.authorizedKeys.keys = with import ../ssh-keys.nix; [ eelco rob ];
112 + users.extraUsers.hydra-www.openssh.authorizedKeys.keys = with import ../ssh-keys.nix; [ eelco rob ];
113 + users.extraUsers.hydra-queue-runner.openssh.authorizedKeys.keys = with import ../ssh-keys.nix; [ eelco rob ];
114
115 users.extraUsers.rbvermaa =
116 { description = "Rob Vermaas";
@@ -119,4 +119,31 @@
119 openssh.authorizedKeys.keys = [ (import ../ssh-keys.nix).rob ];
120 };
121
122 + nix.gc.automatic = true;
123 + nix.gc.options = ''--max-freed "$((700 * 1024**3 - 1024 * $(df -P -k /nix/store | tail -n 1 | ${pkgs.gawk}/bin/awk '{ print $4 }')))"'';
124 +
125 + # Hydra configuration.
126 + services.hydra.enable = true;
127 + services.hydra.logo = ./hydra-logo.png;
128 + services.hydra.dbi = "dbi:Pg:dbname=hydra;host=wendy;user=hydra;";
129 + services.hydra.hydraURL = "http://hydra.nixos.org";
130 + services.hydra.notificationSender = "e.dolstra@tudelft.nl"; # FIXME
131 + services.hydra.extraConfig =
132 + ''
133 + max_servers 50
134 + enable_persona 1
135 +
136 + binary_cache_secret_key_file = /var/lib/hydra/www/keys/hydra.nixos.org-1/secret
137 +
138 + <hipchat>
139 + jobs = (hydra|nixops):.*:.*
140 + room = 182482
141 + token = ${builtins.readFile ./hipchat-lb-token}
142 + </hipchat>
143 + '';
144 +
145 + #services.hydra.package = builtins.storePath /nix/store/qrd493zbpnk8hqs2pc01jac0l715xsd4-hydra-0.1pre1234-abcdef;
146 +
147 + users.extraUsers.hydra.home = mkForce "/home/hydra";
148 +
149 }