about summary refs log tree commit diff
path: root/modules/nixos/promtail.nix
blob: 552df82cb85aefe735f9fdc5d56383994f5b7a6b (plain) (blame)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
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