1 { lib, config, pkgs, ... }:
3 cfg = config.myServices.databases.redis;
5 options.myServices.databases.redis = {
6 enable = lib.mkOption {
9 description = "Whether to enable redis database";
10 type = lib.types.bool;
12 socketsDir = lib.mkOption {
13 type = lib.types.path;
14 default = "/run/redis";
16 The directory where Redis puts sockets.
20 sockets = lib.mkOption {
21 type = lib.types.attrsOf lib.types.path;
23 redis = "${cfg.socketsDir}/redis.sock";
32 config = lib.mkIf cfg.enable {
33 users.users.redis.uid = config.ids.uids.redis;
34 users.groups.redis.gid = config.ids.gids.redis;
35 services.redis = rec {
38 unixSocket = cfg.sockets.redis;
44 systemd.services.redis.serviceConfig.Slice = "redis.slice";
50 source = "0.0.0.0:16379";
51 target = "/run/redis/redis.sock";
52 keyfile = config.secrets.fullPaths."redis/spiped_keyfile";
55 systemd.services.spiped_redis = {
56 description = "Secure pipe 'redis'";
57 after = [ "network.target" ];
58 wantedBy = [ "multi-user.target" ];
61 Slice = "redis.slice";
64 PermissionsStartOnly = true;
65 SupplementaryGroups = "keys";
68 script = "exec ${pkgs.spiped}/bin/spiped -F `cat /etc/spiped/redis.spec`";
71 services.filesWatcher.predixy = {
73 paths = [ config.secrets.fullPaths."redis/predixy.conf" ];
76 networking.firewall.allowedTCPPorts = [ 7617 16379 ];
78 "redis/predixy.conf" = {
89 Auth "${config.myEnv.databases.redis.predixy.read}" {
94 StandaloneServerPool {
98 + ${config.myEnv.databases.redis.socket}
103 "redis/spiped_keyfile" = {
106 permissions = "0400";
107 text = config.myEnv.databases.redis.spiped_key;
111 systemd.slices.redis = {
112 description = "Redis slice";
115 systemd.services.predixy = {
116 description = "Redis proxy";
117 wantedBy = [ "multi-user.target" ];
118 after = [ "redis.service" ];
121 Slice = "redis.slice";
124 SupplementaryGroups = "keys";
127 ExecStart = "${pkgs.predixy}/bin/predixy ${config.secrets.fullPaths."redis/predixy.conf"}";