git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #108440 from aanderse/nixos/redis

nixos/redis: replace extraConfig option with settings option

commit9414948a5a19463acce5a7f2b2206c39ecb6359f authorFlorian Klink <flokli@flokli.de> dateFri 8 Jan 2021, 00:33 (6 years ago) parent610ec6f1a828f6
1 file changed+49−29
nixos/modules/services/databases/redis.nix+49−29
nixos/modules/services/databases/redis.nix+49−29
@@ -4,31 +4,16 @@ with lib;
44
55let
66 cfg = config.services.redis;
7− redisBool = b: if b then "yes" else "no";
8− condOption = name: value: if value != null then "${name} ${toString value}" else "";
9−
10− redisConfig = pkgs.writeText "redis.conf" ''
11− port ${toString cfg.port}
12− ${condOption "bind" cfg.bind}
13− ${condOption "unixsocket" cfg.unixSocket}
14− daemonize no
15− supervised systemd
16− loglevel ${cfg.logLevel}
17− logfile ${cfg.logfile}
18− syslog-enabled ${redisBool cfg.syslog}
19− databases ${toString cfg.databases}
20− ${concatMapStrings (d: "save ${toString (builtins.elemAt d 0)} ${toString (builtins.elemAt d 1)}\n") cfg.save}
21− dbfilename dump.rdb
22− dir /var/lib/redis
23− ${if cfg.slaveOf != null then "slaveof ${cfg.slaveOf.ip} ${toString cfg.slaveOf.port}" else ""}
24− ${condOption "masterauth" cfg.masterAuth}
25− ${condOption "requirepass" cfg.requirePass}
26− appendOnly ${redisBool cfg.appendOnly}
27− appendfsync ${cfg.appendFsync}
28− slowlog-log-slower-than ${toString cfg.slowLogLogSlowerThan}
29− slowlog-max-len ${toString cfg.slowLogMaxLen}
30− ${cfg.extraConfig}
31− '';
7+
8+ mkValueString = value:
9+ if value == true then "yes"
10+ else if value == false then "no"
11+ else generators.mkValueStringDefault { } value;
12+
13+ redisConfig = pkgs.writeText "redis.conf" (generators.toKeyValue {
14+ listsAsDuplicateKeys = true;
15+ mkKeyValue = generators.mkKeyValueDefault { inherit mkValueString; } " ";
16+ } cfg.settings);
3217in
3318{
3419 imports = [
@@ -37,6 +22,7 @@ in
3722 (mkRemovedOptionModule [ "services" "redis" "dbFilename" ] "The redis module now uses /var/lib/redis/dump.rdb as database dump location.")
3823 (mkRemovedOptionModule [ "services" "redis" "appendOnlyFilename" ] "This option was never used.")
3924 (mkRemovedOptionModule [ "services" "redis" "pidFile" ] "This option was removed.")
25+ (mkRemovedOptionModule [ "services" "redis" "extraConfig" ] "Use services.redis.settings instead.")
4026 ];
4127
4228 ###### interface
@@ -191,10 +177,20 @@ in
191177 description = "Maximum number of items to keep in slow log.";
192178 };
193179
194− extraConfig = mkOption {
195− type = types.lines;
196− default = "";
197− description = "Extra configuration options for redis.conf.";
180+ settings = mkOption {
181+ type = with types; attrsOf (oneOf [ bool int str (listOf str) ]);
182+ default = {};
183+ description = ''
184+ Redis configuration. Refer to
185+ <link xlink:href="https://redis.io/topics/config"/>
186+ for details on supported values.
187+ '';
188+ example = literalExample ''
189+ {
190+ unixsocketperm = "700";
191+ loadmodule = [ "/path/to/my_module.so" "/path/to/other_module.so" ];
192+ }
193+ '';
198194 };
199195 };
200196
@@ -225,6 +221,30 @@ in
225221
226222 environment.systemPackages = [ cfg.package ];
227223
224+ services.redis.settings = mkMerge [
225+ {
226+ port = cfg.port;
227+ daemonize = false;
228+ supervised = "systemd";
229+ loglevel = cfg.logLevel;
230+ logfile = cfg.logfile;
231+ syslog-enabled = cfg.syslog;
232+ databases = cfg.databases;
233+ save = map (d: "${toString (builtins.elemAt d 0)} ${toString (builtins.elemAt d 1)}") cfg.save;
234+ dbfilename = "dump.rdb";
235+ dir = "/var/lib/redis";
236+ appendOnly = cfg.appendOnly;
237+ appendfsync = cfg.appendFsync;
238+ slowlog-log-slower-than = cfg.slowLogLogSlowerThan;
239+ slowlog-max-len = cfg.slowLogMaxLen;
240+ }
241+ (mkIf (cfg.bind != null) { bind = cfg.bind; })
242+ (mkIf (cfg.unixSocket != null) { unixsocket = cfg.unixSocket; })
243+ (mkIf (cfg.slaveOf != null) { slaveof = "${cfg.slaveOf.ip} ${cfg.slaveOf.port}"; })
244+ (mkIf (cfg.masterAuth != null) { masterauth = cfg.masterAuth; })
245+ (mkIf (cfg.requirePass != null) { requirepass = cfg.requirePass; })
246+ ];
247+
228248 systemd.services.redis = {
229249 description = "Redis Server";
230250