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