about summary refs log tree commit diff
path: root/nixos/modules/services/monitoring/mimir.nix
diff options
context:
space:
mode:
authorhappysalada <raphael@megzari.com>2022-04-28 19:11:19 -0400
committerYt <raphael@megzari.com>2022-04-29 07:23:03 -0400
commita4707b645feb946265b7a780f55e3e77bfbab14d (patch)
treefdc4f6e2796022053e931dc91191ea69b92c90fc /nixos/modules/services/monitoring/mimir.nix
parent8750fbd0e1580ec2ac3c3ed40504fcc86d83eee8 (diff)
grafana-mimir: add initial module
Diffstat (limited to 'nixos/modules/services/monitoring/mimir.nix')
-rw-r--r--nixos/modules/services/monitoring/mimir.nix63
1 files changed, 63 insertions, 0 deletions
diff --git a/nixos/modules/services/monitoring/mimir.nix b/nixos/modules/services/monitoring/mimir.nix
new file mode 100644
index 0000000000000..df853f037ee6a
--- /dev/null
+++ b/nixos/modules/services/monitoring/mimir.nix
@@ -0,0 +1,63 @@
+{ config, lib, pkgs, ... }:
+
+let
+  inherit (lib) escapeShellArgs mkEnableOption mkIf mkOption types;
+
+  cfg = config.services.mimir;
+
+  settingsFormat = pkgs.formats.yaml {};
+in {
+  options.services.mimir = {
+    enable = mkEnableOption "mimir";
+
+    configuration = mkOption {
+      type = (pkgs.formats.json {}).type;
+      default = {};
+      description = ''
+        Specify the configuration for Mimir in Nix.
+      '';
+    };
+
+    configFile = mkOption {
+      type = types.nullOr types.path;
+      default = null;
+      description = ''
+        Specify a configuration file that Mimir should use.
+      '';
+    };
+  };
+
+  config = mkIf cfg.enable {
+    assertions = [{
+      assertion = (
+        (cfg.configuration == {} -> cfg.configFile != null) &&
+        (cfg.configFile != null -> cfg.configuration == {})
+      );
+      message  = ''
+        Please specify either
+        'services.mimir.configuration' or
+        'services.mimir.configFile'.
+      '';
+    }];
+
+    systemd.services.mimir = {
+      description = "mimir Service Daemon";
+      wantedBy = [ "multi-user.target" ];
+
+      serviceConfig = let
+        conf = if cfg.configFile == null
+               then settingsFormat.generate "config.yaml" cfg.configuration
+               else cfg.configFile;
+      in
+      {
+        ExecStart = "${pkgs.grafana-mimir}/bin/mimir --config.file=${conf}";
+        DynamicUser = true;
+        Restart = "always";
+        ProtectSystem = "full";
+        DevicePolicy = "closed";
+        NoNewPrivileges = true;
+        StateDirectory = "mimir";
+      };
+    };
+  };
+}