git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #67845 from flokli/redis-module

nixos/redis: unbreak module, add test

commit15f3e4eb814e7701492762326ebcfc8b21543a4d authorFlorian Klink <flokli@flokli.de> dateSun 1 Sep 2019, 18:30 (7 years ago) parent9334ce1c00c4b1
5 files changed+55−47
nixos/doc/manual/release-notes/rl-1909.xml+8 nixos/modules/rename.nix+8−1 nixos/modules/services/databases/redis.nix+12−46 nixos/tests/all-tests.nix+1 nixos/tests/redis.nix+26
nixos/doc/manual/release-notes/rl-1909.xml+8
@@ -599,6 +599,14 @@
599599 package and <literal>crashplan-small-business</literal> service have been
600600 removed from nixpkgs due to lack of maintainer.
601601 </para>
602+ <para>
603+ The <link linkend="opt-services.redis.enable">redis module</link> was hardcoded to use the <literal>redis</literal> user,
604+ <filename class="directory">/run/redis</filename> as runtime directory and
605+ <filename class="directory">/var/lib/redis</filename> as state directory.
606+ Note that the NixOS module for Redis now disables kernel support for Transparent Huge Pages (THP),
607+ because this features causes major performance problems for Redis,
608+ e.g. (https://redis.io/topics/latency).
609+ </para>
602610 </listitem>
603611 <listitem>
604612 <para>
nixos/modules/rename.nix+8−1
@@ -256,7 +256,7 @@ with lib;
256256
257257 # binfmt
258258 (mkRenamedOptionModule [ "boot" "binfmtMiscRegistrations" ] [ "boot" "binfmt" "registrations" ])
259−
259+
260260 # ACME
261261 (mkRemovedOptionModule [ "security" "acme" "directory"] "ACME Directory is now hardcoded to /var/lib/acme and its permisisons are managed by systemd. See https://github.com/NixOS/nixpkgs/issues/53852 for more info.")
262262 (mkRemovedOptionModule [ "security" "acme" "preDelay"] "This option has been removed. If you want to make sure that something executes before certificates are provisioned, add a RequiredBy=acme-\${cert}.service to the service you want to execute before the cert renewal")
@@ -285,6 +285,13 @@ with lib;
285285 throw "services.redshift.longitude is set to null, you can remove this"
286286 else builtins.fromJSON value))
287287
288+ # Redis
289+ (mkRemovedOptionModule [ "services" "redis" "user" ] "The redis module now is hardcoded to the redis user.")
290+ (mkRemovedOptionModule [ "services" "redis" "dbpath" ] "The redis module now uses /var/lib/redis as data directory.")
291+ (mkRemovedOptionModule [ "services" "redis" "dbFilename" ] "The redis module now uses /var/lib/redis/dump.rdb as database dump location.")
292+ (mkRemovedOptionModule [ "services" "redis" "appendOnlyFilename" ] "This option was never used.")
293+ (mkRemovedOptionModule [ "services" "redis" "pidFile" ] "This option was removed.")
294+
288295 ] ++ (forEach [ "blackboxExporter" "collectdExporter" "fritzboxExporter"
289296 "jsonExporter" "minioExporter" "nginxExporter" "nodeExporter"
290297 "snmpExporter" "unifiExporter" "varnishExporter" ]
nixos/modules/services/databases/redis.nix+12−46
@@ -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
nixos/tests/all-tests.nix+1
@@ -234,6 +234,7 @@ in
234234 rabbitmq = handleTest ./rabbitmq.nix {};
235235 radarr = handleTest ./radarr.nix {};
236236 radicale = handleTest ./radicale.nix {};
237+ redis = handleTest ./redis.nix {};
237238 redmine = handleTest ./redmine.nix {};
238239 roundcube = handleTest ./roundcube.nix {};
239240 rspamd = handleTest ./rspamd.nix {};
nixos/tests/redis.nixnew file+26
@@ -0,0 +1,26 @@
1+import ./make-test.nix ({ pkgs, ...} : {
2+ name = "redis";
3+ meta = with pkgs.stdenv.lib.maintainers; {
4+ maintainers = [ flokli ];
5+ };
6+
7+ nodes = {
8+ machine =
9+ { pkgs, ... }:
10+
11+ {
12+ services.redis.enable = true;
13+ services.redis.unixSocket = "/run/redis/redis.sock";
14+ };
15+ };
16+
17+ testScript = ''
18+ startAll;
19+
20+ $machine->waitForUnit("redis");
21+ $machine->waitForOpenPort("6379");
22+
23+ $machine->succeed("redis-cli ping | grep PONG");
24+ $machine->succeed("redis-cli -s /run/redis/redis.sock ping | grep PONG");
25+ '';
26+})