zaphyra's git: nixfiles

zaphyra and void's nixfiles

commit d89873976a8e64db0a03fe7443d45195e70a12a0
parent 820805adcce2ec6014f3c32ef34ac2b6a0ec83f8
Author: Katja (zaphyra) <git@ctu.cx>
Date: Thu, 22 May 2025 08:10:13 +0200

config/nixos/modules/services: add `prometheus-exporters`
2 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/config/nixos/modules/presets/katja/enable.nix b/config/nixos/modules/presets/katja/enable.nix
@@ -50,7 +50,7 @@ in
           enable = lib.mkDefault true;
           enableRSASupport = lib.mkDefault true;
         };
-#        prometheus-exporters.enable = lib.mkDefault true;
+        prometheus-exporters.enable = lib.mkDefault true;
       };
     };
 
diff --git a/config/nixos/modules/services/prometheus-exporters.nix b/config/nixos/modules/services/prometheus-exporters.nix
@@ -0,0 +1,50 @@
+{
+  povSelf,
+  config,
+  lib,
+  ...
+}:
+let
+  inherit (lib) types;
+  cfg = lib.getAttrFromPath povSelf config;
+
+in
+{
+
+  options = {
+    enable = {
+      type = types.bool;
+      default = false;
+    };
+  };
+
+  config = lib.mkIf cfg.enable {
+    services = {
+      prometheus.exporters = {
+        node = {
+          enable = true;
+          listenAddress = "[::1]";
+          port = 9100;
+          enabledCollectors = [
+            "systemd"
+            "processes"
+          ];
+        };
+
+        systemd = {
+          enable = true;
+          listenAddress = "[::1]";
+          port = 9558;
+        };
+      };
+
+      nginx.virtualHosts."${config.networking.fqdn}".locations = {
+        "/node-exporter".proxyPass =
+          "http://${toString config.services.prometheus.exporters.node.listenAddress}:${toString config.services.prometheus.exporters.node.port}/metrics";
+        "/systemd-exporter".proxyPass =
+          "http://${toString config.services.prometheus.exporters.systemd.listenAddress}:${toString config.services.prometheus.exporters.systemd.port}/metrics";
+      };
+    };
+  };
+
+}