1# NixOS module for Buildbot Worker. 2 3{ config, lib, pkgs, ... }: 4 5with lib; 6 7let 8 cfg = config.services.buildbot-worker; 9 10in { 11 options = { 12 services.buildbot-worker = { 13 14 enable = mkOption { 15 type = types.bool; 16 default = false; 17 description = "Whether to enable the Buildbot Worker."; 18 }; 19 20 user = mkOption { 21 default = "bbworker"; 22 type = types.str; 23 description = "User the buildbot Worker should execute under."; 24 }; 25 26 group = mkOption { 27 default = "bbworker"; 28 type = types.str; 29 description = "Primary group of buildbot Worker user."; 30 }; 31 32 extraGroups = mkOption { 33 type = types.listOf types.str; 34 default = []; 35 description = "List of extra groups that the Buildbot Worker user should be a part of."; 36 }; 37 38 home = mkOption { 39 default = "/home/bbworker"; 40 type = types.path; 41 description = "Buildbot home directory."; 42 }; 43 44 buildbotDir = mkOption { 45 default = "${cfg.home}/worker"; 46 type = types.path; 47 description = "Specifies the Buildbot directory."; 48 }; 49 50 workerUser = mkOption { 51 default = "example-worker"; 52 type = types.str; 53 description = "Specifies the Buildbot Worker user."; 54 }; 55 56 workerPass = mkOption { 57 default = "pass"; 58 type = types.str; 59 description = "Specifies the Buildbot Worker password."; 60 }; 61 62 masterUrl = mkOption { 63 default = "localhost:9989"; 64 type = types.str; 65 description = "Specifies the Buildbot Worker connection string."; 66 }; 67 68 package = mkOption { 69 type = types.package; 70 default = pkgs.buildbot-worker; 71 defaultText = "pkgs.buildbot-worker"; 72 description = "Package to use for buildbot worker."; 73 example = literalExample "pkgs.buildbot-worker"; 74 }; 75 76 packages = mkOption { 77 default = with pkgs; [ python27Packages.twisted git ]; 78 example = literalExample "[ pkgs.git ]"; 79 type = types.listOf types.package; 80 description = "Packages to add to PATH for the buildbot process."; 81 }; 82 83 }; 84 }; 85 86 config = mkIf cfg.enable { 87 users.extraGroups = optional (cfg.group == "bbworker") { 88 name = "bbworker"; 89 }; 90 91 users.extraUsers = optional (cfg.user == "bbworker") { 92 name = "bbworker"; 93 description = "Buildbot Worker User."; 94 isNormalUser = true; 95 createHome = true; 96 home = cfg.home; 97 group = cfg.group; 98 extraGroups = cfg.extraGroups; 99 useDefaultShell = true; 100 }; 101 102 systemd.services.buildbot-worker = { 103 description = "Buildbot Worker."; 104 after = [ "network.target" "buildbot-master.service" ]; 105 wantedBy = [ "multi-user.target" ]; 106 path = cfg.packages; 107 108 preStart = '' 109 mkdir -vp ${cfg.buildbotDir} 110 rm -fv $cfg.buildbotDir}/buildbot.tac 111 ${cfg.package}/bin/buildbot-worker create-worker ${cfg.buildbotDir} ${cfg.masterUrl} ${cfg.workerUser} ${cfg.workerPass} 112 ''; 113 114 serviceConfig = { 115 Type = "simple"; 116 User = cfg.user; 117 Group = cfg.group; 118 WorkingDirectory = cfg.home; 119 Environment = "PYTHONPATH=${cfg.package}/lib/python2.7/site-packages:${pkgs.python27Packages.future}/lib/python2.7/site-packages"; 120 121 # NOTE: call twistd directly with stdout logging for systemd 122 #ExecStart = "${cfg.package}/bin/buildbot-worker start --nodaemon ${cfg.buildbotDir}"; 123 ExecStart = "${pkgs.python27Packages.twisted}/bin/twistd -n -l - -y ${cfg.buildbotDir}/buildbot.tac"; 124 }; 125 126 }; 127 }; 128 129 meta.maintainers = with lib.maintainers; [ nand0p ]; 130 131}