aboutsummaryrefslogtreecommitdiff
path: root/nixos/profiles/server/prometheus-sql-exporter.nix
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2026-10-17 11:14:02 +0200
committerMartin Fischer <martin@push-f.com>2026-10-18 07:25:43 +0200
commit9237328fb09b2c18365bb5fcef1c4596d77973a9 (patch)
tree55bbfd35140871166a52bbf01bb658c03ca127d6 /nixos/profiles/server/prometheus-sql-exporter.nix
parentf29ddff912ddcd58a4726736702b24655505ce09 (diff)
refactor: make server packages buildable via packages.*
Diffstat (limited to 'nixos/profiles/server/prometheus-sql-exporter.nix')
-rw-r--r--nixos/profiles/server/prometheus-sql-exporter.nix39
1 files changed, 39 insertions, 0 deletions
diff --git a/nixos/profiles/server/prometheus-sql-exporter.nix b/nixos/profiles/server/prometheus-sql-exporter.nix
new file mode 100644
index 0000000..fe2ef7b
--- /dev/null
+++ b/nixos/profiles/server/prometheus-sql-exporter.nix
@@ -0,0 +1,39 @@
+# TODO: submit burningalchemist's sql_exporter to nixpkgs
+{ config, lib, pkgs, sources, ... }:
+
+let
+ sqlExporter = pkgs.callPackage ./pkgs/prometheus-sql-exporter.nix { inherit sources; };
+ 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"];
+ };
+ };
+}