2016-09-17 13:08:18 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.gitlab-runner;
|
|
|
|
configFile = pkgs.writeText "config.toml" cfg.configText;
|
2017-05-11 22:29:09 +02:00
|
|
|
hasDocker = config.virtualisation.docker.enable;
|
2016-09-17 13:08:18 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.gitlab-runner = {
|
|
|
|
enable = mkEnableOption "Gitlab Runner";
|
|
|
|
|
|
|
|
configText = mkOption {
|
|
|
|
description = "Verbatim config.toml to use";
|
|
|
|
};
|
|
|
|
|
|
|
|
workDir = mkOption {
|
|
|
|
default = "/var/lib/gitlab-runner";
|
|
|
|
type = types.path;
|
|
|
|
description = "The working directory used";
|
|
|
|
};
|
|
|
|
|
2017-03-23 22:45:23 +01:00
|
|
|
package = mkOption {
|
|
|
|
description = "Gitlab Runner package to use";
|
|
|
|
default = pkgs.gitlab-runner;
|
|
|
|
defaultText = "pkgs.gitlab-runner";
|
|
|
|
type = types.package;
|
|
|
|
example = literalExample "pkgs.gitlab-runner_1_11";
|
|
|
|
};
|
|
|
|
|
2016-09-17 13:08:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.gitlab-runner = {
|
|
|
|
description = "Gitlab Runner";
|
2017-05-11 22:29:09 +02:00
|
|
|
after = [ "network.target" ]
|
|
|
|
++ optional hasDocker "docker.service";
|
|
|
|
requires = optional hasDocker "docker.service";
|
2016-09-17 13:08:18 +02:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
2017-03-23 22:45:23 +01:00
|
|
|
ExecStart = ''${cfg.package.bin}/bin/gitlab-runner run \
|
2016-09-17 13:08:18 +02:00
|
|
|
--working-directory ${cfg.workDir} \
|
|
|
|
--config ${configFile} \
|
|
|
|
--service gitlab-runner \
|
|
|
|
--user gitlab-runner \
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-03-23 22:45:23 +01:00
|
|
|
# Make the gitlab-runner command availabe so users can query the runner
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
2016-09-17 13:08:18 +02:00
|
|
|
users.extraUsers.gitlab-runner = {
|
|
|
|
group = "gitlab-runner";
|
2017-05-11 22:29:09 +02:00
|
|
|
extraGroups = optional hasDocker "docker";
|
2016-09-17 13:08:18 +02:00
|
|
|
uid = config.ids.uids.gitlab-runner;
|
|
|
|
home = cfg.workDir;
|
|
|
|
createHome = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraGroups.gitlab-runner.gid = config.ids.gids.gitlab-runner;
|
|
|
|
};
|
|
|
|
}
|