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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
{ config, lib, pkgs, ... }:
with import <stockholm/lib>;
let
cfg = config.krebs.ci;
out = {
options.krebs.ci = api;
config = lib.mkIf cfg.enable imp;
};
api = {
enable = mkEnableOption "Enable krebs ci service";
repos = mkOption {
type = types.attrsOf (types.submodule ({ config, ...}: {
options = {
urls = mkOption {
type = types.listOf types.str;
default = [ "git@localhost:${config._module.args.name}" ];
};
};
}));
};
};
hostname = config.networking.hostName;
getJobs = pkgs.writeDash "get_jobs" ''
nix-build --no-out-link --quiet -Q ./ci.nix > /dev/null
nix-instantiate --quiet -Q --eval --strict --json ./ci.nix
'';
imp = {
krebs.buildbot.master = {
slaves = {
testslave = "lasspass";
};
change_source = mapAttrs' (name: repo:
nameValuePair name (concatMapStrings (url: ''
cs.append(
changes.GitPoller(
"${url}",
workdir='${name}-${elemAt(splitString "." url) 1}', branches=True,
project='${name}',
pollinterval=10
)
)
'') repo.urls)
) cfg.repos;
scheduler = mapAttrs' (name: repo:
nameValuePair name ''
sched.append(
schedulers.SingleBranchScheduler(
change_filter=util.ChangeFilter(branch_re=".*"),
treeStableTimer=60,
name="build-all-branches",
builderNames=[
"${name}",
]
)
)
sched.append(
schedulers.ForceScheduler(
name="${name}",
builderNames=[
"${name}",
]
)
)
''
) cfg.repos;
builder_pre = ''
from buildbot import interfaces
from buildbot.steps.shell import ShellCommand
class StepToStartMoreSteps(ShellCommand):
def __init__(self, **kwargs):
ShellCommand.__init__(self, **kwargs)
def addBuildSteps(self, steps_factories):
for sf in steps_factories:
step = interfaces.IBuildStepFactory(sf).buildStep()
step.setBuild(self.build)
step.setBuildSlave(self.build.slavebuilder.slave)
step_status = self.build.build_status.addStepWithName(step.name)
step.setStepStatus(step_status)
self.build.steps.append(step)
def start(self):
props = self.build.getProperties()
new_steps = json.loads(props.getProperty('steps_json'))
for new_step in new_steps:
self.addBuildSteps([steps.ShellCommand(
name=str(new_step),
command=[
new_steps[new_step]
],
timeout=90001,
workdir='build', # TODO figure out why we need this?
)])
ShellCommand.start(self)
'';
builder = mapAttrs' (name: repo:
nameValuePair name ''
f_${name} = util.BuildFactory()
f_${name}.addStep(steps.Git(
repourl=util.Property('repository', '${head repo.urls}'),
mode='full',
submodules=True,
))
f_${name}.addStep(steps.SetPropertyFromCommand(
env={
"NIX_REMOTE": "daemon",
"NIX_PATH": "secrets=/var/src/stockholm/null:/var/src",
},
name="get_steps",
command=["${getJobs}"],
property="steps_json"
))
f_${name}.addStep(StepToStartMoreSteps(command=["echo"])) # TODO remove dummy command from here
bu.append(
util.BuilderConfig(
name="${name}",
slavenames=slavenames,
factory=f_${name}
)
)
''
) cfg.repos;
enable = true;
web.enable = true;
irc = {
enable = true;
nick = "build|${hostname}";
server = "irc.r";
channels = [ "xxx" "noise" ];
allowForce = true;
};
extraConfig = ''
c['buildbotURL'] = "http://build.${hostname}.r/"
'';
};
krebs.buildbot.slave = {
enable = true;
masterhost = "localhost";
username = "testslave";
password = "lasspass";
packages = with pkgs; [ gnumake jq nix populate gnutar lzma gzip ];
};
};
in out
|