summaryrefslogtreecommitdiff
path: root/ofborg/service.nix
blob: 82909250066aec87493387cf2606e6bb75da4484 (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
{ config, lib, pkgs, ... }:

let
  cfg = config.services.tickborg;
  tickborg = (import ./flake.nix).packages.${pkgs.system}.tickborg;

  # Her servis icin ortak systemd ayarlari
  commonServiceConfig = {
    User = "tickborg";
    Group = "tickborg";
    PrivateTmp = true;
    ProtectSystem = "strict";
    ProtectHome = true;
    NoNewPrivileges = true;
    ReadWritePaths = [
      "/var/lib/tickborg"
      "/var/log/tickborg"
    ];
    WorkingDirectory = "/var/lib/tickborg";
    Restart = "always";
    RestartSec = 10;
    Environment = [
      "RUST_LOG=tickborg=info"
      "RUST_BACKTRACE=1"
    ];
  };

  # Her servis icin ortak birim ozellikleri
  mkTickborgService = name: extraConfig: {
    enable = cfg.enable;
    after = [ "network-online.target" "rabbitmq.service" ];
    wants = [ "network-online.target" ];
    wantedBy = [ "multi-user.target" ];
    description = "Tickborg ${name}";

    path = with pkgs; [
      git
      bash
      cmake
      gnumake
      gcc
      pkg-config
      # Meson icin
      meson
      ninja
      # Autotools icin
      autoconf
      automake
      libtool
      # Java/Gradle icin
      jdk17
      # Cargo icin
      rustc
      cargo
    ];

    serviceConfig = commonServiceConfig // (extraConfig.serviceConfig or {});

    script = ''
      export HOME=/var/lib/tickborg
      git config --global user.email "tickborg@project-tick.dev"
      git config --global user.name "TickBorg"
      exec ${tickborg}/bin/${extraConfig.binary} ${cfg.configFile}
    '';
  };

in {
  options.services.tickborg = {
    enable = lib.mkEnableOption "Tickborg CI bot servisleri";

    configFile = lib.mkOption {
      type = lib.types.path;
      default = "/etc/tickborg/config.json";
      description = "Tickborg yapilandirma dosyasi yolu";
    };

    enableBuilder = lib.mkOption {
      type = lib.types.bool;
      default = true;
      description = "Builder servisini etkinlestir";
    };

    enableWebhook = lib.mkOption {
      type = lib.types.bool;
      default = true;
      description = "Webhook receiver servisini etkinlestir";
    };

    enableEvaluationFilter = lib.mkOption {
      type = lib.types.bool;
      default = true;
      description = "Evaluation filter servisini etkinlestir";
    };

    enableCommentFilter = lib.mkOption {
      type = lib.types.bool;
      default = true;
      description = "Comment filter servisini etkinlestir";
    };

    enableCommentPoster = lib.mkOption {
      type = lib.types.bool;
      default = true;
      description = "Comment poster servisini etkinlestir";
    };

    enableMassRebuilder = lib.mkOption {
      type = lib.types.bool;
      default = false;
      description = "Mass rebuilder servisini etkinlestir";
    };

    enableLogCollector = lib.mkOption {
      type = lib.types.bool;
      default = true;
      description = "Log collector servisini etkinlestir";
    };

    enableStats = lib.mkOption {
      type = lib.types.bool;
      default = true;
      description = "Stats (Prometheus metrics) servisini etkinlestir";
    };
  };

  config = lib.mkIf cfg.enable {
    users.users.tickborg = {
      description = "Tickborg CI Bot";
      home = "/var/lib/tickborg";
      createHome = true;
      group = "tickborg";
      isSystemUser = true;
    };
    users.groups.tickborg = {};

    systemd.tmpfiles.rules = [
      "d /var/lib/tickborg 0750 tickborg tickborg -"
      "d /var/lib/tickborg/checkout 0750 tickborg tickborg -"
      "d /var/log/tickborg 0750 tickborg tickborg -"
    ];

    systemd.services = lib.mkMerge [
      (lib.mkIf cfg.enableWebhook {
        "tickborg-webhook-receiver" = mkTickborgService "Webhook Receiver" {
          binary = "github_webhook_receiver";
        };
      })

      (lib.mkIf cfg.enableEvaluationFilter {
        "tickborg-evaluation-filter" = mkTickborgService "Evaluation Filter" {
          binary = "evaluation_filter";
        };
      })

      (lib.mkIf cfg.enableCommentFilter {
        "tickborg-comment-filter" = mkTickborgService "Comment Filter" {
          binary = "github_comment_filter";
        };
      })

      (lib.mkIf cfg.enableCommentPoster {
        "tickborg-comment-poster" = mkTickborgService "Comment Poster" {
          binary = "github_comment_poster";
        };
      })

      (lib.mkIf cfg.enableBuilder {
        "tickborg-builder" = mkTickborgService "Builder" {
          binary = "builder";
          serviceConfig = {
            # Builder daha fazla kaynak kullanabilir
            MemoryMax = "8G";
            CPUQuota = "400%";
          };
        };
      })

      (lib.mkIf cfg.enableMassRebuilder {
        "tickborg-mass-rebuilder" = mkTickborgService "Mass Rebuilder" {
          binary = "mass_rebuilder";
        };
      })

      (lib.mkIf cfg.enableLogCollector {
        "tickborg-log-collector" = mkTickborgService "Log Collector" {
          binary = "log_message_collector";
        };
      })

      (lib.mkIf cfg.enableStats {
        "tickborg-stats" = mkTickborgService "Stats" {
          binary = "stats";
        };
      })
    ];
  };
}