about summary refs log tree commit diff
path: root/modules/services/drone/runner-docker/default.nix
blob: d701c188be94abbef0c1637327926f7fc4d53426 (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
{ config, lib, pkgs, ... }:
let
  cfg = config.my.services.drone;
  hasRunner = (name: builtins.elem name cfg.runners);
  dockerPkg = pkgs.drone-runner-docker;
in {
  config = lib.mkIf (cfg.enable && hasRunner "docker") {
    systemd.services.drone-runner-docker = {
      wantedBy = [ "multi-user.target" ];
      after = [ "docker.socket" ]; # Needs the socket to be available
      # might break deployment
      restartIfChanged = false;
      confinement.enable = true;
      serviceConfig = {
        Environment = [
          "DRONE_SERVER_HOST=${cfg.vhostName}"
          "DRONE_SERVER_PROTO=https"
          "DRONE_RUNNER_CAPACITY=10"
          "CLIENT_DRONE_RPC_HOST=127.0.0.1:${toString cfg.port}"
        ];
        BindPaths = [ "/var/run/docker.sock" ];
        EnvironmentFile = [ cfg.sharedSecretFile ];
        ExecStart = "${dockerPkg}/bin/drone-runner-docker";
        User = "drone-runner-docker";
        Group = "drone-runner-docker";
      };
    };

    # Make sure it is activated in that case
    virtualisation.docker.enable = true;

    users.users.drone-runner-docker = {
      isSystemUser = true;
      group = "drone-runner-docker";
      extraGroups = [ "docker" ]; # Give access to the daemon
    };
    users.groups.drone-runner-docker = { };
  };
}