-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathredis.nix
More file actions
122 lines (113 loc) · 3.09 KB
/
Copy pathredis.nix
File metadata and controls
122 lines (113 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
{
config,
pkgs,
lib,
...
}:
{
# create some options
options.services.redis =
let
inherit (lib) mkOption types;
in
{
enable = lib.mkEnableOption "Enable Redis.";
bind = mkOption {
type = with types; listOf str;
description = "List of IPs to bind to.";
default = [
"127.0.0.1"
"::1"
];
};
port = mkOption {
type = types.ints.between 1024 65535;
description = "Port to bind to.";
default = 6379;
};
socket = mkOption {
type = with types; nullOr str;
description = "Unix socket to bind to. Relative paths are placed under the service runtime run directory; absolute paths are used as-is.";
default = null;
};
socketPerms = mkOption {
type = with types; nullOr int;
description = "Permissions for the unix socket.";
default = null;
};
logLevel = mkOption {
type = types.enum [
"debug"
"verbose"
"notice"
"warning"
"nothing"
];
description = "Logging verbosity level.";
default = "notice";
};
databases = mkOption {
type = types.int;
description = "Number of databases.";
default = 16;
};
# escape hatch due to redis config being massive
extraConfig = mkOption {
type = types.str;
description = "Additional config directives.";
default = "";
};
name = mkOption {
type = types.str;
description = "The name ides uses for this service.";
default = "redis";
};
};
config.serviceDefs =
let
cfg = config.services.redis;
in
lib.mkIf cfg.enable {
# 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";
argv = [ { config = "main"; } ];
configs.main.runtime = {
fileName = "redis.conf";
parts =
[
"bind ${lib.concatStringsSep " " cfg.bind}\n"
"port ${toString cfg.port}\n"
"databases ${toString cfg.databases}\n"
"loglevel ${cfg.logLevel}\n"
"dir "
{ runtimePath = "data"; }
"\n"
"pidfile "
{ runtimePath = "run"; }
"/redis.pid\n"
]
++ lib.optionals (cfg.socket != null) (
if lib.hasPrefix "/" cfg.socket then
[
"unixsocket ${cfg.socket}\n"
]
else
[
"unixsocket "
{ runtimePath = "run"; }
"/${cfg.socket}\n"
]
)
++ lib.optionals (cfg.socket != null && cfg.socketPerms != null) [
"unixsocketperm ${toString cfg.socketPerms}\n"
]
++ lib.optionals (cfg.extraConfig != "") [
cfg.extraConfig
];
};
};
};
}