about summary refs log tree commit diff
path: root/modules/nixos/promtail.nix
diff options
context:
space:
mode:
Diffstat (limited to 'modules/nixos/promtail.nix')
-rw-r--r--modules/nixos/promtail.nix53
1 files changed, 53 insertions, 0 deletions
diff --git a/modules/nixos/promtail.nix b/modules/nixos/promtail.nix
new file mode 100644
index 0000000..552df82
--- /dev/null
+++ b/modules/nixos/promtail.nix
@@ -0,0 +1,53 @@
+{
+  config,
+  lib,
+  this,
+  ...
+}:
+with lib; let
+  cfg = config.nixfiles.modules.promtail;
+in {
+  options.nixfiles.modules.promtail = {
+    enable = mkEnableOption "Promtail";
+
+    loki = {
+      url = mkOption {
+        description = "Address of a listening Loki service.";
+        type = with types; str;
+        default = "https://${config.nixfiles.modules.loki.domain}";
+      };
+    };
+  };
+
+  config = mkIf cfg.enable {
+    services.promtail = {
+      enable = true;
+
+      configuration = {
+        server = rec {
+          http_listen_address = this.wireguard.ipv4.address;
+          http_listen_port = 30181;
+
+          grpc_listen_address = this.wireguard.ipv4.address;
+          grpc_listen_port = http_listen_port + 1;
+
+          log_level = "warn";
+        };
+
+        clients = [{url = "${cfg.loki.url}/loki/api/v1/push";}];
+
+        positions.filename = "/tmp/positions.yaml";
+
+        scrape_configs = [
+          {
+            job_name = "journal";
+            journal = {
+              max_age = "24h";
+              labels.job = "systemd-journal";
+            };
+          }
+        ];
+      };
+    };
+  };
+}

Consider giving Nix/NixOS a try! <3