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;
49 source = "0.0.0.0:16379";
50 target = "/run/redis/redis.sock";
51 keyfile = "${config.secrets.location}/redis/spiped_keyfile";
54 systemd.services.spiped_redis = {
55 description = "Secure pipe 'redis'";
56 after = [ "network.target" ];
57 wantedBy = [ "multi-user.target" ];
62 PermissionsStartOnly = true;
63 SupplementaryGroups = "keys";
66 script = "exec ${pkgs.spiped}/bin/spiped -F `cat /etc/spiped/redis.spec`";
69 services.filesWatcher.predixy = {
71 paths = [ "${config.secrets.location}/redis/predixy.conf" ];
74 networking.firewall.allowedTCPPorts = [ 7617 16379 ];
77 dest = "redis/predixy.conf";
88 Auth "${config.myEnv.databases.redis.predixy.read}" {
93 StandaloneServerPool {
97 + ${config.myEnv.databases.redis.socket}
103 dest = "redis/spiped_keyfile";
106 permissions = "0400";
107 text = config.myEnv.databases.redis.spiped_key;
111 systemd.services.predixy = {
112 description = "Redis proxy";
113 wantedBy = [ "multi-user.target" ];
114 after = [ "redis.service" ];
119 SupplementaryGroups = "keys";
122 ExecStart = "${pkgs.predixy}/bin/predixy ${config.secrets.location}/redis/predixy.conf";