1{
2 config,
3 lib,
4 pkgs,
5 utils,
6 ...
7}:
8
9let
10 inherit (lib)
11 mkEnableOption
12 mkIf
13 mkOption
14 mkPackageOption
15 types
16 ;
17
18 cfg = config.services.pgscv;
19
20 settingsFormat = pkgs.formats.yaml { };
21 configFile = settingsFormat.generate "config.yaml" cfg.settings;
22in
23{
24 options.services.pgscv = {
25 enable = mkEnableOption "pgSCV, a PostgreSQL ecosystem metrics collector";
26
27 package = mkPackageOption pkgs "pgscv" { };
28
29 logLevel = mkOption {
30 type = types.enum [
31 "debug"
32 "info"
33 "warn"
34 "error"
35 ];
36 default = "info";
37 description = "Log level for pgSCV.";
38 };
39
40 settings = mkOption {
41 type = settingsFormat.type;
42 default = { };
43 description = ''
44 Configuration for pgSCV, in YAML format.
45
46 See [configuration reference](https://github.com/cherts/pgscv/wiki/Configuration-settings-reference).
47 '';
48 };
49 };
50
51 config = mkIf cfg.enable {
52 systemd.services.pgscv = {
53 description = "pgSCV - PostgreSQL ecosystem metrics collector";
54 wantedBy = [ "multi-user.target" ];
55 requires = [ "network-online.target" ];
56 after = [ "network-online.target" ];
57 path = [ pkgs.glibc ]; # shells out to getconf
58
59 serviceConfig = {
60 User = "postgres";
61 Group = "postgres";
62 ExecStart = utils.escapeSystemdExecArgs [
63 (lib.getExe cfg.package)
64 "--log-level=${cfg.logLevel}"
65 "--config-file=${configFile}"
66 ];
67 KillMode = "control-group";
68 TimeoutSec = 5;
69 Restart = "on-failure";
70 RestartSec = 10;
71 OOMScoreAdjust = 1000;
72 };
73 };
74 };
75}