summary refs log tree commit diff
path: root/nixos/modules/services/continuous-integration/gitlab-runner.nix
blob: 1fe4d28f9f357620b5272d5af7437ed068cd348e (plain) (blame)
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
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.gitlab-runner;
  configFile = pkgs.writeText "config.toml" cfg.configText;
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";
    };

  };

  config = mkIf cfg.enable {
    systemd.services.gitlab-runner = {
      description = "Gitlab Runner";
      after = [ "network.target" "docker.service" ];
      requires = [ "docker.service" ];
      wantedBy = [ "multi-user.target" ];
      serviceConfig = {
        ExecStart = ''${pkgs.gitlab-runner.bin}/bin/gitlab-runner run \
          --working-directory ${cfg.workDir} \
          --config ${configFile} \
          --service gitlab-runner \
          --user gitlab-runner \
        '';
      };
    };

    users.extraUsers.gitlab-runner = {
      group = "gitlab-runner";
      extraGroups = [ "docker" ];
      uid = config.ids.uids.gitlab-runner;
      home = cfg.workDir;
      createHome = true;
    };

    users.extraGroups.gitlab-runner.gid = config.ids.gids.gitlab-runner;
  };
}