blob: a79528c8c236076128fb31764325a4af1e5d02ce (
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
|
# TODO: submit burningalchemist's sql_exporter to nixpkgs
{ config, lib, pkgs, ... }:
let
sqlExporter = pkgs.callPackage ./default.nix {};
cfg = config.services.prometheus-sql-exporter;
configFile = builtins.toFile "config.yaml" (builtins.toJSON cfg.config);
validateConfig = file:
pkgs.runCommand "validate-config"
{
nativeBuildInputs = [sqlExporter];
}
''
sql_exporter -config.check -config.file "${file}"
ln -s "${file}" "$out"
'';
in
{
options.services.prometheus-sql-exporter = {
enable = lib.mkEnableOption "sql-exporter";
port = lib.mkOption {
type = lib.types.int;
};
config = lib.mkOption {
type = (pkgs.formats.json {}).type;
};
};
config = lib.mkIf cfg.enable {
systemd.services.prometheus-sql-exporter = {
serviceConfig = {
ExecStart = "${sqlExporter}/bin/sql_exporter -config.file ${validateConfig configFile} -web.listen-address :${toString cfg.port}";
DynamicUser = "true";
User = "prometheus-sql-exporter";
};
wantedBy = ["multi-user.target"];
};
};
}
|