about summary refs log tree commit diff
path: root/modules/nixos/redis.nix
blob: ca2510129a273a09617d55c237fd3f6919afb0af (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
{
  config,
  lib,
  this,
  ...
}:
with lib; let
  cfg = config.nixfiles.modules.redis;
in {
  options.nixfiles.modules.redis.enable = mkEnableOption "Redis";

  config = mkIf cfg.enable {
    ark.directories = ["/var/lib/redis-default"];

    services = {
      redis = {
        servers.default = {
          enable = true;
          bind = "127.0.0.1";
          port = 6379;
        };
        vmOverCommit = true;
      };

      prometheus.exporters = {
        redis = {
          enable = true;
          listenAddress = mkDefault this.wireguard.ipv4.address;
          port = mkDefault 9121;
          extraFlags = with config.services.redis.servers.default; [
            "--redis.addr=redis://${bind}:${toString port}"
            "--redis.user=${user}"
          ];
        };
      };
    };
  };
}

Consider giving Nix/NixOS a try! <3