2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-06-07 09:34:05 +00:00
|
|
|
|
2014-04-14 14:26:48 +00:00
|
|
|
with lib;
|
2013-06-07 09:34:05 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.redis;
|
2021-01-05 00:47:32 +00:00
|
|
|
|
|
|
|
mkValueString = value:
|
|
|
|
if value == true then "yes"
|
|
|
|
else if value == false then "no"
|
|
|
|
else generators.mkValueStringDefault { } value;
|
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
redisConfig = settings: pkgs.writeText "redis.conf" (generators.toKeyValue {
|
2021-01-05 00:47:32 +00:00
|
|
|
listsAsDuplicateKeys = true;
|
|
|
|
mkKeyValue = generators.mkKeyValueDefault { inherit mkValueString; } " ";
|
2021-08-23 17:57:49 +00:00
|
|
|
} settings);
|
|
|
|
|
|
|
|
redisName = name: "redis" + optionalString (name != "") ("-"+name);
|
|
|
|
enabledServers = filterAttrs (name: conf: conf.enable) config.services.redis.servers;
|
2021-04-12 09:36:28 +00:00
|
|
|
|
|
|
|
in {
|
2019-12-10 01:51:19 +00:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "services" "redis" "user" ] "The redis module now is hardcoded to the redis user.")
|
|
|
|
(mkRemovedOptionModule [ "services" "redis" "dbpath" ] "The redis module now uses /var/lib/redis as data directory.")
|
|
|
|
(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" "pidFile" ] "This option was removed.")
|
2021-08-23 17:57:49 +00:00
|
|
|
(mkRemovedOptionModule [ "services" "redis" "extraConfig" ] "Use services.redis.servers.*.settings instead.")
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "enable"] [ "services" "redis" "servers" "" "enable" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "port"] [ "services" "redis" "servers" "" "port" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "openFirewall"] [ "services" "redis" "servers" "" "openFirewall" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "bind"] [ "services" "redis" "servers" "" "bind" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "unixSocket"] [ "services" "redis" "servers" "" "unixSocket" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "unixSocketPerm"] [ "services" "redis" "servers" "" "unixSocketPerm" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "logLevel"] [ "services" "redis" "servers" "" "logLevel" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "logfile"] [ "services" "redis" "servers" "" "logfile" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "syslog"] [ "services" "redis" "servers" "" "syslog" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "databases"] [ "services" "redis" "servers" "" "databases" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "maxclients"] [ "services" "redis" "servers" "" "maxclients" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "save"] [ "services" "redis" "servers" "" "save" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "slaveOf"] [ "services" "redis" "servers" "" "slaveOf" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "masterAuth"] [ "services" "redis" "servers" "" "masterAuth" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "requirePass"] [ "services" "redis" "servers" "" "requirePass" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "requirePassFile"] [ "services" "redis" "servers" "" "requirePassFile" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "appendOnly"] [ "services" "redis" "servers" "" "appendOnly" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "appendFsync"] [ "services" "redis" "servers" "" "appendFsync" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "slowLogLogSlowerThan"] [ "services" "redis" "servers" "" "slowLogLogSlowerThan" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "slowLogMaxLen"] [ "services" "redis" "servers" "" "slowLogMaxLen" ])
|
|
|
|
(mkRenamedOptionModule [ "services" "redis" "settings"] [ "services" "redis" "servers" "" "settings" ])
|
2019-12-10 01:51:19 +00:00
|
|
|
];
|
2013-06-07 09:34:05 +00:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.redis = {
|
|
|
|
package = mkOption {
|
2014-05-02 18:49:31 +00:00
|
|
|
type = types.package;
|
2013-06-07 09:34:05 +00:00
|
|
|
default = pkgs.redis;
|
2021-10-03 16:06:03 +00:00
|
|
|
defaultText = literalExpression "pkgs.redis";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Which Redis derivation to use.";
|
2013-06-07 09:34:05 +00:00
|
|
|
};
|
|
|
|
|
2022-08-28 19:18:44 +00:00
|
|
|
vmOverCommit = mkEnableOption (lib.mdDoc ''
|
2021-08-23 17:57:49 +00:00
|
|
|
setting of vm.overcommit_memory to 1
|
|
|
|
(Suggested for Background Saving: http://redis.io/topics/faq)
|
2022-08-28 19:18:44 +00:00
|
|
|
'');
|
2015-10-03 06:22:27 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
servers = mkOption {
|
2022-11-30 22:38:52 +00:00
|
|
|
type = with types; attrsOf (submodule ({ config, name, ... }: {
|
2021-08-23 17:57:49 +00:00
|
|
|
options = {
|
2022-08-28 19:18:44 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc ''
|
2021-08-23 17:57:49 +00:00
|
|
|
Redis server.
|
|
|
|
|
|
|
|
Note that the NixOS module for Redis disables kernel support
|
|
|
|
for Transparent Huge Pages (THP),
|
|
|
|
because this features causes major performance problems for Redis,
|
|
|
|
e.g. (https://redis.io/topics/latency).
|
2022-08-28 19:18:44 +00:00
|
|
|
'');
|
2021-08-23 17:57:49 +00:00
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = redisName name;
|
2022-02-28 12:37:47 +00:00
|
|
|
defaultText = literalExpression ''
|
|
|
|
if name == "" then "redis" else "redis-''${name}"
|
|
|
|
'';
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "The username and groupname for redis-server.";
|
2021-08-23 17:57:49 +00:00
|
|
|
};
|
2015-10-03 06:22:27 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
2022-01-20 22:17:32 +00:00
|
|
|
default = if name == "" then 6379 else 0;
|
|
|
|
defaultText = literalExpression ''if name == "" then 6379 else 0'';
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-01-20 22:17:32 +00:00
|
|
|
The TCP port to accept connections.
|
|
|
|
If port 0 is specified Redis will not listen on a TCP socket.
|
|
|
|
'';
|
2021-08-23 17:57:49 +00:00
|
|
|
};
|
2013-06-07 09:34:05 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-08-23 17:57:49 +00:00
|
|
|
Whether to open ports in the firewall for the server.
|
|
|
|
'';
|
|
|
|
};
|
2013-06-07 09:34:05 +00:00
|
|
|
|
2022-11-09 01:34:11 +00:00
|
|
|
extraParams = mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [];
|
|
|
|
description = lib.mdDoc "Extra parameters to append to redis-server invocation";
|
|
|
|
example = [ "--sentinel" ];
|
|
|
|
};
|
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
bind = mkOption {
|
|
|
|
type = with types; nullOr str;
|
2022-02-28 12:37:47 +00:00
|
|
|
default = "127.0.0.1";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-08-23 17:57:49 +00:00
|
|
|
The IP interface to bind to.
|
2022-07-28 21:19:15 +00:00
|
|
|
`null` means "all interfaces".
|
2021-08-23 17:57:49 +00:00
|
|
|
'';
|
|
|
|
example = "192.0.2.1";
|
|
|
|
};
|
2021-03-24 10:13:47 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
unixSocket = mkOption {
|
|
|
|
type = with types; nullOr path;
|
|
|
|
default = "/run/${redisName name}/redis.sock";
|
2022-02-28 12:37:47 +00:00
|
|
|
defaultText = literalExpression ''
|
|
|
|
if name == "" then "/run/redis/redis.sock" else "/run/redis-''${name}/redis.sock"
|
|
|
|
'';
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "The path to the socket to bind to.";
|
2021-08-23 17:57:49 +00:00
|
|
|
};
|
2013-06-07 09:34:05 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
unixSocketPerm = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 660;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Change permissions for the socket";
|
2021-08-23 17:57:49 +00:00
|
|
|
example = 600;
|
|
|
|
};
|
2013-06-07 09:34:05 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
logLevel = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "notice"; # debug, verbose, notice, warning
|
|
|
|
example = "debug";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Specify the server verbosity level, options: debug, verbose, notice, warning.";
|
2021-08-23 17:57:49 +00:00
|
|
|
};
|
2013-10-28 17:14:49 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
logfile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/dev/null";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Specify the log file name. Also 'stdout' can be used to force Redis to log on the standard output.";
|
2021-08-23 17:57:49 +00:00
|
|
|
example = "/var/log/redis.log";
|
|
|
|
};
|
2013-06-07 09:34:05 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
syslog = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Enable logging to the system logger.";
|
2021-08-23 17:57:49 +00:00
|
|
|
};
|
2021-04-12 09:36:28 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
databases = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 16;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Set the number of databases.";
|
2021-08-23 17:57:49 +00:00
|
|
|
};
|
2013-06-07 09:34:05 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
maxclients = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 10000;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Set the max number of connected clients at the same time.";
|
2019-12-29 23:06:23 +00:00
|
|
|
};
|
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
save = mkOption {
|
|
|
|
type = with types; listOf (listOf int);
|
|
|
|
default = [ [900 1] [300 10] [60 10000] ];
|
2022-07-04 15:47:31 +00:00
|
|
|
description = mdDoc ''
|
|
|
|
The schedule in which data is persisted to disk, represented as a list of lists where the first element represent the amount of seconds and the second the number of changes.
|
|
|
|
|
|
|
|
If set to the empty list (`[]`) then RDB persistence will be disabled (useful if you are using AOF or don't want any persistence).
|
|
|
|
'';
|
2019-12-29 23:06:23 +00:00
|
|
|
};
|
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
slaveOf = mkOption {
|
|
|
|
type = with types; nullOr (submodule ({ ... }: {
|
|
|
|
options = {
|
|
|
|
ip = mkOption {
|
|
|
|
type = str;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "IP of the Redis master";
|
2021-08-23 17:57:49 +00:00
|
|
|
example = "192.168.1.100";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = port;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "port of the Redis master";
|
2021-08-23 17:57:49 +00:00
|
|
|
default = 6379;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
|
|
|
|
default = null;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "IP and port to which this redis instance acts as a slave.";
|
2021-08-23 17:57:49 +00:00
|
|
|
example = { ip = "192.168.1.100"; port = 6379; };
|
|
|
|
};
|
2013-06-07 09:34:05 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
masterAuth = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''If the master is password protected (using the requirePass configuration)
|
2021-08-23 17:57:49 +00:00
|
|
|
it is possible to tell the slave to authenticate before starting the replication synchronization
|
|
|
|
process, otherwise the master will refuse the slave request.
|
|
|
|
(STORED PLAIN TEXT, WORLD-READABLE IN NIX STORE)'';
|
|
|
|
};
|
2013-06-07 09:34:05 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
requirePass = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-08-23 17:57:49 +00:00
|
|
|
Password for database (STORED PLAIN TEXT, WORLD-READABLE IN NIX STORE).
|
|
|
|
Use requirePassFile to store it outside of the nix store in a dedicated file.
|
|
|
|
'';
|
|
|
|
example = "letmein!";
|
|
|
|
};
|
2013-06-07 09:34:05 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
requirePassFile = mkOption {
|
|
|
|
type = with types; nullOr path;
|
|
|
|
default = null;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "File with password for the database.";
|
2021-08-23 17:57:49 +00:00
|
|
|
example = "/run/keys/redis-password";
|
|
|
|
};
|
2020-02-13 15:56:29 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
appendOnly = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "By default data is only periodically persisted to disk, enable this option to use an append-only file for improved persistence.";
|
2021-08-23 17:57:49 +00:00
|
|
|
};
|
2013-06-07 09:34:05 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
appendFsync = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "everysec"; # no, always, everysec
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "How often to fsync the append-only log, options: no, always, everysec.";
|
2021-08-23 17:57:49 +00:00
|
|
|
};
|
2013-06-07 09:34:05 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
slowLogLogSlowerThan = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 10000;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Log queries whose execution take longer than X in milliseconds.";
|
2021-08-23 17:57:49 +00:00
|
|
|
example = 1000;
|
|
|
|
};
|
2013-06-07 09:34:05 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
slowLogMaxLen = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 128;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Maximum number of items to keep in slow log.";
|
2021-08-23 17:57:49 +00:00
|
|
|
};
|
2013-06-17 18:06:02 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
settings = mkOption {
|
|
|
|
# TODO: this should be converted to freeformType
|
|
|
|
type = with types; attrsOf (oneOf [ bool int str (listOf str) ]);
|
|
|
|
default = {};
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-08-23 17:57:49 +00:00
|
|
|
Redis configuration. Refer to
|
2022-07-28 21:19:15 +00:00
|
|
|
<https://redis.io/topics/config>
|
2021-08-23 17:57:49 +00:00
|
|
|
for details on supported values.
|
|
|
|
'';
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
loadmodule = [ "/path/to/my_module.so" "/path/to/other_module.so" ];
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
config.settings = mkMerge [
|
|
|
|
{
|
2022-11-30 22:38:52 +00:00
|
|
|
inherit (config) port logfile databases maxclients appendOnly;
|
2021-08-23 17:57:49 +00:00
|
|
|
daemonize = false;
|
|
|
|
supervised = "systemd";
|
|
|
|
loglevel = config.logLevel;
|
|
|
|
syslog-enabled = config.syslog;
|
2022-07-04 15:47:31 +00:00
|
|
|
save = if config.save == []
|
|
|
|
then ''""'' # Disable saving with `save = ""`
|
|
|
|
else map
|
|
|
|
(d: "${toString (builtins.elemAt d 0)} ${toString (builtins.elemAt d 1)}")
|
|
|
|
config.save;
|
2021-08-23 17:57:49 +00:00
|
|
|
dbfilename = "dump.rdb";
|
|
|
|
dir = "/var/lib/${redisName name}";
|
|
|
|
appendfsync = config.appendFsync;
|
|
|
|
slowlog-log-slower-than = config.slowLogLogSlowerThan;
|
|
|
|
slowlog-max-len = config.slowLogMaxLen;
|
|
|
|
}
|
2022-11-30 22:38:52 +00:00
|
|
|
(mkIf (config.bind != null) { inherit (config) bind; })
|
2021-08-23 17:57:49 +00:00
|
|
|
(mkIf (config.unixSocket != null) {
|
|
|
|
unixsocket = config.unixSocket;
|
|
|
|
unixsocketperm = toString config.unixSocketPerm;
|
|
|
|
})
|
|
|
|
(mkIf (config.slaveOf != null) { slaveof = "${config.slaveOf.ip} ${toString config.slaveOf.port}"; })
|
|
|
|
(mkIf (config.masterAuth != null) { masterauth = config.masterAuth; })
|
|
|
|
(mkIf (config.requirePass != null) { requirepass = config.requirePass; })
|
|
|
|
];
|
|
|
|
}));
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Configuration of multiple `redis-server` instances.";
|
2021-01-05 00:47:32 +00:00
|
|
|
default = {};
|
2013-06-17 18:06:02 +00:00
|
|
|
};
|
2013-06-07 09:34:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
config = mkIf (enabledServers != {}) {
|
|
|
|
|
|
|
|
assertions = attrValues (mapAttrs (name: conf: {
|
|
|
|
assertion = conf.requirePass != null -> conf.requirePassFile == null;
|
|
|
|
message = ''
|
|
|
|
You can only set one services.redis.servers.${name}.requirePass
|
|
|
|
or services.redis.servers.${name}.requirePassFile
|
|
|
|
'';
|
|
|
|
}) enabledServers);
|
|
|
|
|
|
|
|
boot.kernel.sysctl = mkMerge [
|
2019-11-08 14:37:30 +00:00
|
|
|
{ "vm.nr_hugepages" = "0"; }
|
|
|
|
( mkIf cfg.vmOverCommit { "vm.overcommit_memory" = "1"; } )
|
2021-08-23 17:57:49 +00:00
|
|
|
];
|
2015-10-03 06:22:27 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
networking.firewall.allowedTCPPorts = concatMap (conf:
|
|
|
|
optional conf.openFirewall conf.port
|
|
|
|
) (attrValues enabledServers);
|
2013-06-07 09:34:05 +00:00
|
|
|
|
2013-06-07 09:37:58 +00:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
2013-06-07 09:34:05 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
users.users = mapAttrs' (name: conf: nameValuePair (redisName name) {
|
|
|
|
description = "System user for the redis-server instance ${name}";
|
|
|
|
isSystemUser = true;
|
|
|
|
group = redisName name;
|
|
|
|
}) enabledServers;
|
|
|
|
users.groups = mapAttrs' (name: conf: nameValuePair (redisName name) {
|
|
|
|
}) enabledServers;
|
2021-01-05 00:47:32 +00:00
|
|
|
|
2021-08-23 17:57:49 +00:00
|
|
|
systemd.services = mapAttrs' (name: conf: nameValuePair (redisName name) {
|
|
|
|
description = "Redis Server - ${redisName name}";
|
2013-06-07 09:34:05 +00:00
|
|
|
|
2020-02-13 15:56:29 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
2013-06-07 09:34:05 +00:00
|
|
|
|
2020-02-13 15:56:29 +00:00
|
|
|
serviceConfig = {
|
2022-11-09 01:35:39 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/redis-server /var/lib/${redisName name}/redis.conf ${escapeShellArgs conf.extraParams}";
|
|
|
|
ExecStartPre = "+"+pkgs.writeShellScript "${redisName name}-prep-conf" (let
|
|
|
|
redisConfVar = "/var/lib/${redisName name}/redis.conf";
|
|
|
|
redisConfRun = "/run/${redisName name}/nixos.conf";
|
|
|
|
redisConfStore = redisConfig conf.settings;
|
|
|
|
in ''
|
|
|
|
touch "${redisConfVar}" "${redisConfRun}"
|
|
|
|
chown '${conf.user}' "${redisConfVar}" "${redisConfRun}"
|
|
|
|
chmod 0600 "${redisConfVar}" "${redisConfRun}"
|
|
|
|
if [ ! -s ${redisConfVar} ]; then
|
|
|
|
echo 'include "${redisConfRun}"' > "${redisConfVar}"
|
|
|
|
fi
|
|
|
|
echo 'include "${redisConfStore}"' > "${redisConfRun}"
|
|
|
|
${optionalString (conf.requirePassFile != null) ''
|
2022-11-21 17:00:12 +00:00
|
|
|
{
|
|
|
|
echo -n "requirepass "
|
|
|
|
cat ${escapeShellArg conf.requirePassFile}
|
|
|
|
} >> "${redisConfRun}"
|
2022-11-09 01:35:39 +00:00
|
|
|
''}
|
|
|
|
'');
|
2020-02-13 15:56:29 +00:00
|
|
|
Type = "notify";
|
2021-03-24 10:33:34 +00:00
|
|
|
# User and group
|
2021-08-23 17:57:49 +00:00
|
|
|
User = conf.user;
|
|
|
|
Group = conf.user;
|
2021-03-24 10:33:34 +00:00
|
|
|
# Runtime directory and mode
|
2021-08-23 17:57:49 +00:00
|
|
|
RuntimeDirectory = redisName name;
|
2021-03-24 10:33:34 +00:00
|
|
|
RuntimeDirectoryMode = "0750";
|
|
|
|
# State directory and mode
|
2021-08-23 17:57:49 +00:00
|
|
|
StateDirectory = redisName name;
|
2021-03-24 10:33:34 +00:00
|
|
|
StateDirectoryMode = "0700";
|
|
|
|
# Access write directories
|
|
|
|
UMask = "0077";
|
2021-04-03 20:00:48 +00:00
|
|
|
# Capabilities
|
|
|
|
CapabilityBoundingSet = "";
|
|
|
|
# Security
|
|
|
|
NoNewPrivileges = true;
|
2021-04-12 09:36:28 +00:00
|
|
|
# Process Properties
|
2021-08-23 17:57:49 +00:00
|
|
|
LimitNOFILE = mkDefault "${toString (conf.maxclients + 32)}";
|
2021-04-03 20:00:48 +00:00
|
|
|
# Sandboxing
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
ProtectHome = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectControlGroups = true;
|
2021-08-23 17:57:49 +00:00
|
|
|
RestrictAddressFamilies =
|
2022-02-28 12:37:47 +00:00
|
|
|
optionals (conf.port != 0) ["AF_INET" "AF_INET6"] ++
|
2021-08-23 17:57:49 +00:00
|
|
|
optional (conf.unixSocket != null) "AF_UNIX";
|
2021-04-03 20:00:48 +00:00
|
|
|
RestrictNamespaces = true;
|
|
|
|
LockPersonality = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
PrivateMounts = true;
|
|
|
|
# System Call Filtering
|
|
|
|
SystemCallArchitectures = "native";
|
2021-05-13 12:29:25 +00:00
|
|
|
SystemCallFilter = "~@cpu-emulation @debug @keyring @memlock @mount @obsolete @privileged @resources @setuid";
|
2020-02-13 15:56:29 +00:00
|
|
|
};
|
2021-08-23 17:57:49 +00:00
|
|
|
}) enabledServers;
|
|
|
|
|
2013-06-07 09:34:05 +00:00
|
|
|
};
|
|
|
|
}
|