@@ -8,17 +8,19 @@ let
88 condOption = name: value: if value != null then "${name} ${toString value}" else "";
99
1010 redisConfig = pkgs.writeText "redis.conf" ''
11− pidfile ${cfg.pidFile}
1211 port ${toString cfg.port}
1312 ${condOption "bind" cfg.bind}
1413 ${condOption "unixsocket" cfg.unixSocket}
14+ daemonize yes
15+ supervised systemd
1516 loglevel ${cfg.logLevel}
1617 logfile ${cfg.logfile}
1718 syslog-enabled ${redisBool cfg.syslog}
19+ pidfile /run/redis/redis.pid
1820 databases ${toString cfg.databases}
1921 ${concatMapStrings (d: "save ${toString (builtins.elemAt d 0)} ${toString (builtins.elemAt d 1)}\n") cfg.save}
20− dbfilename ${cfg.dbFilename}
21− dir ${toString cfg.dbpath}
22+ dbfilename dump.rdb
23+ dir /var/lib/redis
2224 ${if cfg.slaveOf != null then "slaveof ${cfg.slaveOf.ip} ${toString cfg.slaveOf.port}" else ""}
2325 ${condOption "masterauth" cfg.masterAuth}
2426 ${condOption "requirepass" cfg.requirePass}
@@ -55,18 +57,6 @@ in
5557 description = "Which Redis derivation to use.";
5658 };
5759
58− user = mkOption {
59− type = types.str;
60− default = "redis";
61− description = "User account under which Redis runs.";
62− };
63−
64− pidFile = mkOption {
65− type = types.path;
66− default = "/var/lib/redis/redis.pid";
67− description = "";
68− };
69−
7060 port = mkOption {
7161 type = types.int;
7262 default = 6379;
@@ -100,7 +90,7 @@ in
10090 type = with types; nullOr path;
10191 default = null;
10292 description = "The path to the socket to bind to.";
103− example = "/run/redis.sock";
93+ example = "/run/redis/redis.sock";
10494 };
10595
10696 logLevel = mkOption {
@@ -136,18 +126,6 @@ in
136126 example = [ [900 1] [300 10] [60 10000] ];
137127 };
138128
139− dbFilename = mkOption {
140− type = types.str;
141− default = "dump.rdb";
142− description = "The filename where to dump the DB.";
143− };
144−
145− dbpath = mkOption {
146− type = types.path;
147− default = "/var/lib/redis";
148− description = "The DB will be written inside this directory, with the filename specified using the 'dbFilename' configuration.";
149− };
150−
151129 slaveOf = mkOption {
152130 default = null; # { ip, port }
153131 description = "An attribute set with two attributes: ip and port to which this redis instance acts as a slave.";
@@ -175,12 +153,6 @@ in
175153 description = "By default data is only periodically persisted to disk, enable this option to use an append-only file for improved persistence.";
176154 };
177155
178− appendOnlyFilename = mkOption {
179− type = types.str;
180− default = "appendonly.aof";
181− description = "Filename for the append-only file (stored inside of dbpath)";
182− };
183−
184156 appendFsync = mkOption {
185157 type = types.str;
186158 default = "everysec"; # no, always, everysec
@@ -222,19 +194,15 @@ in
222194 allowedTCPPorts = [ cfg.port ];
223195 };
224196
225− users.users.redis =
226− { name = cfg.user;
227− description = "Redis database user";
228− };
197+ users.users.redis.description = "Redis database user";
229198
230199 environment.systemPackages = [ cfg.package ];
231200
232201 systemd.services.disable-transparent-huge-pages = {
233− enable = config.services.redis.enable;
234202 description = "Disable Transparent Huge Pages (required by Redis)";
235203 before = [ "redis.service" ];
236204 wantedBy = [ "redis.service" ];
237− script = "echo never >/sys/kernel/mm/transparent_hugepage/enabled";
205+ script = "echo never > /sys/kernel/mm/transparent_hugepage/enabled";
238206 serviceConfig.Type = "oneshot";
239207 };
240208
@@ -244,14 +212,12 @@ in
244212 wantedBy = [ "multi-user.target" ];
245213 after = [ "network.target" ];
246214
247− preStart = ''
248− install -d -m0700 -o ${cfg.user} ${cfg.dbpath}
249− chown -R ${cfg.user} ${cfg.dbpath}
250− '';
251−
252215 serviceConfig = {
253216 ExecStart = "${cfg.package}/bin/redis-server ${redisConfig}";
254− User = cfg.user;
217+ RuntimeDirectory = "redis";
218+ StateDirectory = "redis";
219+ Type = "notify";
220+ User = "redis";
255221 };
256222 };
257223