-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathsnabb_bot.nix
95 lines (79 loc) · 2.53 KB
/
snabb_bot.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{ config, pkgs, lib, ... }:
with lib;
with pkgs;
let
snabb_bot = writeScript "snabb_bot.sh" (readFile (fetchurl {
url = "https://raw.githubusercontent.com/eugeneia/snabb/b6bed3018fe0b076867a9f644f393fdc3ae251a3/src/scripts/snabb_bot.sh";
sha256 = "344630fb6ac0dab500e16b41759ea401b079304ae473ff88cfe37f3767a0d326";
}));
in {
options = {
services.snabb_bot = {
credentials = lib.mkOption {
type = types.str;
default = "";
description = ''
GitHub credentials for SnabbBot instance.
'';
example = ''
username:password
'';
};
repo = lib.mkOption {
type = types.str;
default = "SnabbCo/snabb";
description = ''
Target GitHub repository for SnabbBot instance.
'';
};
dir = lib.mkOption {
type = types.str;
default = "/tmp/snabb_bot";
description = ''
Target GitHub repository for SnabbBot instance.
'';
};
current = lib.mkOption {
type = types.str;
default = "master";
description = ''
The branch to merge pull requests with.
'';
};
period = lib.mkOption {
type = types.str;
default = "* * * * *";
description = ''
This option defines (in the format used by cron) when the
SnabbBot runs. The default is every minute.
'';
};
environment = lib.mkOption {
type = types.str;
default = "";
description = ''
This option defines (in shell format, e.g.: `export FOO=bar; ...')
which additional environment variables will be set when
SnabbBot runs.
''; };
};
};
config = {
systemd.services.snabb_bot =
{ description = "Run SnabbBot";
path = [ bash curl git docker jq pciutils busybox ];
script =
''
export GITHUB_CREDENTIALS=${config.services.snabb_bot.credentials}
export REPO=${config.services.snabb_bot.repo}
export SNABBBOTDIR=${config.services.snabb_bot.dir}
export CURRENT=${config.services.snabb_bot.current}
${config.services.snabb_bot.environment}
exec flock -x -n /var/lock/snabb_bot ${snabb_bot}
'';
environment.SSL_CERT_FILE = config.environment.sessionVariables.SSL_CERT_FILE;
};
services.cron.systemCronJobs =
[ "${config.services.snabb_bot.period} root ${config.systemd.package}/bin/systemctl start snabb_bot.service" ];
};
}