update redis module to allow multiple instances
This commit is contained in:
parent
1d3181f16e
commit
ecb61f146f
@ -64,55 +64,64 @@
|
||||
description = "Additional config directives.";
|
||||
default = "";
|
||||
};
|
||||
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
description = "The name ides uses for this service.";
|
||||
default = "redis";
|
||||
};
|
||||
};
|
||||
|
||||
config.serviceDefs.redis =
|
||||
config.serviceDefs =
|
||||
let
|
||||
cfg = config.services.redis;
|
||||
in
|
||||
lib.mkIf cfg.enable {
|
||||
pkg = pkgs.redis;
|
||||
# make sure we get the server binary, not cli
|
||||
exec = "redis-server";
|
||||
args = "%CFG%";
|
||||
config = {
|
||||
ext = ".conf";
|
||||
# these need to be made to match redis config
|
||||
# variable names here
|
||||
content = {
|
||||
inherit (cfg) bind port databases;
|
||||
unixsocket = cfg.socket;
|
||||
unixsocketperm = cfg.socketPerms;
|
||||
loglevel = cfg.logLevel;
|
||||
# use a customisable name in case the user needs several instances
|
||||
"${cfg.name}" = {
|
||||
pkg = pkgs.redis;
|
||||
# make sure we get the server binary, not cli
|
||||
exec = "redis-server";
|
||||
args = "%CFG%";
|
||||
config = {
|
||||
ext = ".conf";
|
||||
# these need to be made to match redis config
|
||||
# variable names here
|
||||
content = {
|
||||
inherit (cfg) bind port databases;
|
||||
unixsocket = cfg.socket;
|
||||
unixsocketperm = cfg.socketPerms;
|
||||
loglevel = cfg.logLevel;
|
||||
};
|
||||
# a formatter needs to take in a set of
|
||||
# attrs and write out a file
|
||||
formatter =
|
||||
let
|
||||
# set up serialisation for all types
|
||||
serialise = {
|
||||
int = builtins.toString;
|
||||
bool = b: if b then "yes" else "no";
|
||||
string = s: s;
|
||||
path = builtins.toString;
|
||||
null = _: _;
|
||||
list = builtins.concatStringsSep " ";
|
||||
float = builtins.toString;
|
||||
set = throw "cannot serialise a set in redis format";
|
||||
lambda = throw "cannot serialise a lambda, wtf?";
|
||||
};
|
||||
in
|
||||
# create a lambda that can serialise to redis config
|
||||
path: attrs:
|
||||
let
|
||||
text =
|
||||
(lib.foldlAttrs (
|
||||
acc: n: v:
|
||||
if (v != null) then acc + "${n} ${serialise.${builtins.typeOf v} v}" + "\n" else acc
|
||||
) "" attrs)
|
||||
+ cfg.extraConfig;
|
||||
in
|
||||
(pkgs.writeText path text).outPath;
|
||||
};
|
||||
# a formatter needs to take in a set of
|
||||
# attrs and write out a file
|
||||
formatter =
|
||||
let
|
||||
# set up serialisation for all types
|
||||
serialise = {
|
||||
int = builtins.toString;
|
||||
bool = b: if b then "yes" else "no";
|
||||
string = s: s;
|
||||
path = builtins.toString;
|
||||
null = _: _;
|
||||
list = builtins.concatStringsSep " ";
|
||||
float = builtins.toString;
|
||||
set = throw "cannot serialise a set in redis format";
|
||||
lambda = throw "cannot serialise a lambda, wtf?";
|
||||
};
|
||||
in
|
||||
# create a lambda that can serialise to redis config
|
||||
path: attrs:
|
||||
let
|
||||
text =
|
||||
(lib.foldlAttrs (
|
||||
acc: n: v:
|
||||
if (v != null) then acc + "${n} ${serialise.${builtins.typeOf v} v}" + "\n" else acc
|
||||
) "" attrs)
|
||||
+ cfg.extraConfig;
|
||||
in
|
||||
(pkgs.writeText path text).outPath;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user