1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8let
9 inherit (lib) mkIf mkOption types;
10 cfg = config.services.jenkinsSlave;
11 masterCfg = config.services.jenkins;
12in
13{
14 options = {
15 services.jenkinsSlave = {
16 # todo:
17 # * assure the profile of the jenkins user has a JRE and any specified packages. This would
18 # enable ssh slaves.
19 # * Optionally configure the node as a jenkins ad-hoc slave. This would imply configuration
20 # properties for the master node.
21 enable = mkOption {
22 type = types.bool;
23 default = false;
24 description = ''
25 If true the system will be configured to work as a jenkins slave.
26 If the system is also configured to work as a jenkins master then this has no effect.
27 In progress: Currently only assures the jenkins user is configured.
28 '';
29 };
30
31 user = mkOption {
32 default = "jenkins";
33 type = types.str;
34 description = ''
35 User the jenkins slave agent should execute under.
36 '';
37 };
38
39 group = mkOption {
40 default = "jenkins";
41 type = types.str;
42 description = ''
43 If the default slave agent user "jenkins" is configured then this is
44 the primary group of that user.
45 '';
46 };
47
48 home = mkOption {
49 default = "/var/lib/jenkins";
50 type = types.path;
51 description = ''
52 The path to use as JENKINS_HOME. If the default user "jenkins" is configured then
53 this is the home of the "jenkins" user.
54 '';
55 };
56
57 javaPackage = lib.mkPackageOption pkgs "jdk" { };
58 };
59 };
60
61 config = mkIf (cfg.enable && !masterCfg.enable) {
62 users.groups = lib.optionalAttrs (cfg.group == "jenkins") {
63 jenkins.gid = config.ids.gids.jenkins;
64 };
65
66 users.users = lib.optionalAttrs (cfg.user == "jenkins") {
67 jenkins = {
68 description = "jenkins user";
69 createHome = true;
70 home = cfg.home;
71 group = cfg.group;
72 useDefaultShell = true;
73 uid = config.ids.uids.jenkins;
74 };
75 };
76
77 programs.java = {
78 enable = true;
79 package = cfg.javaPackage;
80 };
81 };
82}