aboutsummaryrefslogtreecommitdiff
path: root/nixops/modules/databases/redis.nix
blob: 73796854feca30ca0274f21afc1551bf05e632d9 (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
{ lib, pkgs, config, myconfig, mylibs, ... }:
let
    cfg = config.services.myDatabases;
in {
  options.services.myDatabases = {
    redis = {
      enable = lib.mkOption {
        default = cfg.enable;
        example = true;
        description = "Whether to enable redis database";
        type = lib.types.bool;
      };
    };
  };

  config = lib.mkIf cfg.enable {
    ids.uids.redis = myconfig.env.users.redis.uid;
    ids.gids.redis = myconfig.env.users.redis.gid;
    users.users.redis.uid = config.ids.uids.redis;
    users.groups.redis.gid = config.ids.gids.redis;
    services.redis = rec {
      enable = config.services.myDatabases.redis.enable;
      bind = "127.0.0.1";
      unixSocket = myconfig.env.databases.redis.socket;
      extraConfig = ''
        unixsocketperm 777
        maxclients 1024
        '';
    };
    system.activationScripts.redis = ''
      mkdir -p $(dirname ${myconfig.env.databases.redis.socket})
      chown redis $(dirname ${myconfig.env.databases.redis.socket})
    '';

  };
}