about summary refs log tree commit diff
path: root/modules/services/drone/runner-exec/default.nix
blob: 9222200472984e97503423c973a0063ab5364804 (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
52
53
54
{ config, lib, pkgs, ... }:
let
  cfg = config.my.services.drone;
  hasRunner = (name: builtins.elem name cfg.runners);
  execPkg = pkgs.drone-runner-exec;
in {
  config = lib.mkIf (cfg.enable && hasRunner "exec") {
    systemd.services.drone-runner-exec = {
      wantedBy = [ "multi-user.target" ];
      # might break deployment
      restartIfChanged = false;
      confinement.enable = true;
      confinement.packages = with pkgs; [ git gnutar bash nixUnstable gzip ];
      path = with pkgs; [ git gnutar bash nixUnstable gzip ];
      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}"
          "NIX_REMOTE=daemon"
          "PAGER=cat"
        ];
        BindPaths = [ "/nix/var/nix/daemon-socket/socket" ];
        BindReadOnlyPaths = [
          "/etc/resolv.conf:/etc/resolv.conf"
          "/etc/resolvconf.conf:/etc/resolvconf.conf"
          "/etc/passwd:/etc/passwd"
          "/etc/group:/etc/group"
          "/nix/var/nix/profiles/system/etc/nix:/etc/nix"
          "${
            config.environment.etc."ssl/certs/ca-certificates.crt".source
          }:/etc/ssl/certs/ca-certificates.crt"
          "${
            config.environment.etc."ssh/ssh_known_hosts".source
          }:/etc/ssh/ssh_known_hosts"
          "/etc/machine-id"
          # channels are dynamic paths in the nix store, therefore we need to bind mount the whole thing
          "/nix/"
        ];
        EnvironmentFile = [ cfg.sharedSecretFile ];
        ExecStart = "${execPkg}/bin/drone-runner-exec";
        User = "drone-runner-exec";
        Group = "drone-runner-exec";
      };
    };

    users.users.drone-runner-exec = {
      isSystemUser = true;
      group = "drone-runner-exec";
    };
    users.groups.drone-runner-exec = { };
  };
}