about summary refs log tree commit diff
path: root/modules/mimir.nix
blob: 8effa5958ae44512755d76cf57480af12e0d387c (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
{
  config,
  inputs,
  lib,
  libNginx,
  this,
  ...
}:
let
  cfg = config.nixfiles.modules.mimir;
in
{
  options.nixfiles.modules.mimir = {
    enable = lib.mkEnableOption "Mimir";

    port = lib.mkOption {
      description = "Port.";
      type = lib.types.port;
      default = 30161;
    };

    domain = lib.mkOption {
      description = "Domain name sans protocol scheme.";
      type = lib.types.str;
      default = "mimir.${config.networking.domain}";
    };
  };

  config = lib.mkIf cfg.enable {
    nixfiles.modules.nginx = {
      enable = true;
      upstreams.mimir.servers."127.0.0.1:${toString cfg.port}" = { };
      virtualHosts.${cfg.domain} = {
        locations."/".proxyPass = "http://mimir";
        extraConfig = libNginx.config.internalOnly;
      };
    };

    services.mimir = {
      enable = true;
      configuration = rec {
        target = "all,alertmanager";

        enable_go_runtime_metrics = true;

        multitenancy_enabled = false;

        server = {
          http_listen_address = "127.0.0.1";
          http_listen_port = cfg.port;

          # https://github.com/grafana/mimir/discussions/7047
          grpc_listen_address = "0.0.0.0";
          grpc_listen_port = server.http_listen_port + 1;

          log_format = "logfmt";
          log_level = "warn";
          log_source_ips_enabled = true;
        };

        ingester.ring.replication_factor = 1;

        store_gateway.sharding_ring.replication_factor = 1;

        alertmanager.sharding_ring.replication_factor = 1;

        activity_tracker.filepath = "";

        memberlist = {
          bind_port = 7945;
          message_history_buffer_bytes = lib.pow 2 13;
        };

        limits.compactor_blocks_retention_period = "90d";

        usage_stats.enabled = false;
      };
    };

    environment.etc."alloy/mimir.alloy".text = ''
      prometheus.relabel "mimir" {
        rule {
          action        = "replace"
          replacement   = "default/mimir"
          target_label  = "job"
        }
        rule {
          action        = "replace"
          replacement   = "default"
          target_label  = "cluster"
        }
        rule {
          action        = "replace"
          replacement   = "default"
          target_label  = "namespace"
        }
        forward_to = [prometheus.relabel.default.receiver]
      }
      prometheus.scrape "mimir" {
        targets = [
          {
            __address__ = "127.0.0.1:${toString cfg.port}",
            instance    = "${config.networking.hostName}",
          },
        ]
        forward_to = [prometheus.relabel.mimir.receiver]
      }
    '';

    systemd.services.alloy.reloadTriggers = [ config.environment.etc."alloy/mimir.alloy".source ];

    topology.nodes.${this.hostname}.services.mimir = {
      name = "Mimir";
      icon = "${inputs.homelab-svg-assets}/assets/prometheus.svg";
      info = cfg.domain;
      details.listen.text = "127.0.0.1:${toString cfg.port}";
    };
  };
}

Consider giving Nix/NixOS a try! <3