mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-14 06:00:33 +03:00
nixos/redis: replace extraConfig option with settings option
This commit is contained in:
parent
1995d8d919
commit
1a828f66dc
1 changed files with 48 additions and 28 deletions
|
@ -4,31 +4,16 @@ with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.redis;
|
cfg = config.services.redis;
|
||||||
redisBool = b: if b then "yes" else "no";
|
|
||||||
condOption = name: value: if value != null then "${name} ${toString value}" else "";
|
|
||||||
|
|
||||||
redisConfig = pkgs.writeText "redis.conf" ''
|
mkValueString = value:
|
||||||
port ${toString cfg.port}
|
if value == true then "yes"
|
||||||
${condOption "bind" cfg.bind}
|
else if value == false then "no"
|
||||||
${condOption "unixsocket" cfg.unixSocket}
|
else generators.mkValueStringDefault { } value;
|
||||||
daemonize no
|
|
||||||
supervised systemd
|
redisConfig = pkgs.writeText "redis.conf" (generators.toKeyValue {
|
||||||
loglevel ${cfg.logLevel}
|
listsAsDuplicateKeys = true;
|
||||||
logfile ${cfg.logfile}
|
mkKeyValue = generators.mkKeyValueDefault { inherit mkValueString; } " ";
|
||||||
syslog-enabled ${redisBool cfg.syslog}
|
} cfg.settings);
|
||||||
databases ${toString cfg.databases}
|
|
||||||
${concatMapStrings (d: "save ${toString (builtins.elemAt d 0)} ${toString (builtins.elemAt d 1)}\n") cfg.save}
|
|
||||||
dbfilename dump.rdb
|
|
||||||
dir /var/lib/redis
|
|
||||||
${if cfg.slaveOf != null then "slaveof ${cfg.slaveOf.ip} ${toString cfg.slaveOf.port}" else ""}
|
|
||||||
${condOption "masterauth" cfg.masterAuth}
|
|
||||||
${condOption "requirepass" cfg.requirePass}
|
|
||||||
appendOnly ${redisBool cfg.appendOnly}
|
|
||||||
appendfsync ${cfg.appendFsync}
|
|
||||||
slowlog-log-slower-than ${toString cfg.slowLogLogSlowerThan}
|
|
||||||
slowlog-max-len ${toString cfg.slowLogMaxLen}
|
|
||||||
${cfg.extraConfig}
|
|
||||||
'';
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
|
@ -37,6 +22,7 @@ in
|
||||||
(mkRemovedOptionModule [ "services" "redis" "dbFilename" ] "The redis module now uses /var/lib/redis/dump.rdb as database dump location.")
|
(mkRemovedOptionModule [ "services" "redis" "dbFilename" ] "The redis module now uses /var/lib/redis/dump.rdb as database dump location.")
|
||||||
(mkRemovedOptionModule [ "services" "redis" "appendOnlyFilename" ] "This option was never used.")
|
(mkRemovedOptionModule [ "services" "redis" "appendOnlyFilename" ] "This option was never used.")
|
||||||
(mkRemovedOptionModule [ "services" "redis" "pidFile" ] "This option was removed.")
|
(mkRemovedOptionModule [ "services" "redis" "pidFile" ] "This option was removed.")
|
||||||
|
(mkRemovedOptionModule [ "services" "redis" "extraConfig" ] "Use services.redis.settings instead.")
|
||||||
];
|
];
|
||||||
|
|
||||||
###### interface
|
###### interface
|
||||||
|
@ -191,10 +177,20 @@ in
|
||||||
description = "Maximum number of items to keep in slow log.";
|
description = "Maximum number of items to keep in slow log.";
|
||||||
};
|
};
|
||||||
|
|
||||||
extraConfig = mkOption {
|
settings = mkOption {
|
||||||
type = types.lines;
|
type = with types; attrsOf (oneOf [ bool int str (listOf str) ]);
|
||||||
default = "";
|
default = {};
|
||||||
description = "Extra configuration options for redis.conf.";
|
description = ''
|
||||||
|
Redis configuration. Refer to
|
||||||
|
<link xlink:href="https://redis.io/topics/config"/>
|
||||||
|
for details on supported values.
|
||||||
|
'';
|
||||||
|
example = literalExample ''
|
||||||
|
{
|
||||||
|
unixsocketperm = "700";
|
||||||
|
loadmodule = [ "/path/to/my_module.so" "/path/to/other_module.so" ];
|
||||||
|
}
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -225,6 +221,30 @@ in
|
||||||
|
|
||||||
environment.systemPackages = [ cfg.package ];
|
environment.systemPackages = [ cfg.package ];
|
||||||
|
|
||||||
|
services.redis.settings = mkMerge [
|
||||||
|
{
|
||||||
|
port = cfg.port;
|
||||||
|
daemonize = false;
|
||||||
|
supervised = "systemd";
|
||||||
|
loglevel = cfg.logLevel;
|
||||||
|
logfile = cfg.logfile;
|
||||||
|
syslog-enabled = cfg.syslog;
|
||||||
|
databases = cfg.databases;
|
||||||
|
save = map (d: "${toString (builtins.elemAt d 0)} ${toString (builtins.elemAt d 1)}") cfg.save;
|
||||||
|
dbfilename = "dump.rdb";
|
||||||
|
dir = "/var/lib/redis";
|
||||||
|
appendOnly = cfg.appendOnly;
|
||||||
|
appendfsync = cfg.appendFsync;
|
||||||
|
slowlog-log-slower-than = cfg.slowLogLogSlowerThan;
|
||||||
|
slowlog-max-len = cfg.slowLogMaxLen;
|
||||||
|
}
|
||||||
|
(mkIf (cfg.bind != null) { bind = cfg.bind; })
|
||||||
|
(mkIf (cfg.unixSocket != null) { unixsocket = cfg.unixSocket; })
|
||||||
|
(mkIf (cfg.slaveOf != null) { slaveof = "${cfg.slaveOf.ip} ${cfg.slaveOf.port}"; })
|
||||||
|
(mkIf (cfg.masterAuth != null) { masterauth = cfg.masterAuth; })
|
||||||
|
(mkIf (cfg.requirePass != null) { requirepass = cfg.requirePass; })
|
||||||
|
];
|
||||||
|
|
||||||
systemd.services.redis = {
|
systemd.services.redis = {
|
||||||
description = "Redis Server";
|
description = "Redis Server";
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue