1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.trickster;
7in
8{
9 imports = [
10 (mkRenamedOptionModule [ "services" "trickster" "origin" ] [ "services" "trickster" "origin-url" ])
11 ];
12
13 options = {
14 services.trickster = {
15 enable = mkOption {
16 type = types.bool;
17 default = false;
18 description = ''
19 Enable Trickster.
20 '';
21 };
22
23 package = mkPackageOption pkgs "trickster" { };
24
25 configFile = mkOption {
26 type = types.nullOr types.path;
27 default = null;
28 description = ''
29 Path to configuration file.
30 '';
31 };
32
33 instance-id = mkOption {
34 type = types.nullOr types.int;
35 default = null;
36 description = ''
37 Instance ID for when running multiple processes (default null).
38 '';
39 };
40
41 log-level = mkOption {
42 type = types.str;
43 default = "info";
44 description = ''
45 Level of Logging to use (debug, info, warn, error) (default "info").
46 '';
47 };
48
49 metrics-port = mkOption {
50 type = types.port;
51 default = 8082;
52 description = ''
53 Port that the /metrics endpoint will listen on.
54 '';
55 };
56
57 origin-type = mkOption {
58 type = types.enum [ "prometheus" "influxdb" ];
59 default = "prometheus";
60 description = ''
61 Type of origin (prometheus, influxdb)
62 '';
63 };
64
65 origin-url = mkOption {
66 type = types.str;
67 default = "http://prometheus:9090";
68 description = ''
69 URL to the Origin. Enter it like you would in grafana, e.g., http://prometheus:9090 (default http://prometheus:9090).
70 '';
71 };
72
73 profiler-port = mkOption {
74 type = types.nullOr types.port;
75 default = null;
76 description = ''
77 Port that the /debug/pprof endpoint will listen on.
78 '';
79 };
80
81 proxy-port = mkOption {
82 type = types.port;
83 default = 9090;
84 description = ''
85 Port that the Proxy server will listen on.
86 '';
87 };
88
89 };
90 };
91
92 config = mkIf cfg.enable {
93 systemd.services.trickster = {
94 description = "Reverse proxy cache and time series dashboard accelerator";
95 after = [ "network.target" ];
96 wantedBy = [ "multi-user.target" ];
97 serviceConfig = {
98 DynamicUser = true;
99 ExecStart = ''
100 ${cfg.package}/bin/trickster \
101 -log-level ${cfg.log-level} \
102 -metrics-port ${toString cfg.metrics-port} \
103 -origin-type ${cfg.origin-type} \
104 -origin-url ${cfg.origin-url} \
105 -proxy-port ${toString cfg.proxy-port} \
106 ${optionalString (cfg.configFile != null) "-config ${cfg.configFile}"} \
107 ${optionalString (cfg.profiler-port != null) "-profiler-port ${cfg.profiler-port}"} \
108 ${optionalString (cfg.instance-id != null) "-instance-id ${cfg.instance-id}"}
109 '';
110 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
111 Restart = "always";
112 };
113 };
114 };
115
116 meta.maintainers = with maintainers; [ _1000101 ];
117
118}