about summary refs log tree commit diff
path: root/modules/mimir.nix
diff options
context:
space:
mode:
Diffstat (limited to 'modules/mimir.nix')
-rw-r--r--modules/mimir.nix119
1 files changed, 119 insertions, 0 deletions
diff --git a/modules/mimir.nix b/modules/mimir.nix
new file mode 100644
index 0000000..8effa59
--- /dev/null
+++ b/modules/mimir.nix
@@ -0,0 +1,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