| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | { config, lib, pkgs, ... }: | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | with lib; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | let | 
					
						
							|  |  |  |   cfg = config.services.redis; | 
					
						
							| 
									
										
										
										
											2021-01-04 19:47:32 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-12 12:36:28 +03:00
										 |  |  |   ulimitNofile = cfg.maxclients + 32; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-04 19:47:32 -05:00
										 |  |  |   mkValueString = value: | 
					
						
							|  |  |  |     if value == true then "yes" | 
					
						
							|  |  |  |     else if value == false then "no" | 
					
						
							|  |  |  |     else generators.mkValueStringDefault { } value; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   redisConfig = pkgs.writeText "redis.conf" (generators.toKeyValue { | 
					
						
							|  |  |  |     listsAsDuplicateKeys = true; | 
					
						
							|  |  |  |     mkKeyValue = generators.mkKeyValueDefault { inherit mkValueString; } " "; | 
					
						
							|  |  |  |   } cfg.settings); | 
					
						
							| 
									
										
										
										
											2021-04-12 12:36:28 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | in { | 
					
						
							| 
									
										
										
										
											2019-12-10 02:51:19 +01: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-01-04 19:47:32 -05:00
										 |  |  |     (mkRemovedOptionModule [ "services" "redis" "extraConfig" ] "Use services.redis.settings instead.") | 
					
						
							| 
									
										
										
										
											2019-12-10 02:51:19 +01:00
										 |  |  |   ]; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   ###### interface | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   options = { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     services.redis = { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       enable = mkOption { | 
					
						
							| 
									
										
										
										
											2014-05-02 20:49:31 +02:00
										 |  |  |         type = types.bool; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |         default = false; | 
					
						
							| 
									
										
										
										
											2019-08-30 15:44:01 +02:00
										 |  |  |         description = ''
 | 
					
						
							|  |  |  |           Whether to enable the 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). | 
					
						
							|  |  |  |         '';
 | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       package = mkOption { | 
					
						
							| 
									
										
										
										
											2014-05-02 20:49:31 +02:00
										 |  |  |         type = types.package; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |         default = pkgs.redis; | 
					
						
							| 
									
										
										
										
											2016-01-17 19:34:55 +01:00
										 |  |  |         defaultText = "pkgs.redis"; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |         description = "Which Redis derivation to use."; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       port = mkOption { | 
					
						
							| 
									
										
										
										
											2014-05-02 20:49:31 +02:00
										 |  |  |         type = types.int; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |         default = 6379; | 
					
						
							| 
									
										
										
										
											2014-06-24 21:23:14 +02:00
										 |  |  |         description = "The port for Redis to listen to."; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-02 23:22:27 -07:00
										 |  |  |       vmOverCommit = mkOption { | 
					
						
							|  |  |  |         type = types.bool; | 
					
						
							|  |  |  |         default = false; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Set vm.overcommit_memory to 1 (Suggested for Background Saving: http://redis.io/topics/faq) | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       openFirewall = mkOption { | 
					
						
							|  |  |  |         type = types.bool; | 
					
						
							|  |  |  |         default = false; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Whether to open ports in the firewall for the server. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |       bind = mkOption { | 
					
						
							| 
									
										
										
										
											2014-05-02 20:49:31 +02:00
										 |  |  |         type = with types; nullOr str; | 
					
						
							| 
									
										
										
										
											2020-10-11 03:15:19 +02:00
										 |  |  |         default = "127.0.0.1"; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           The IP interface to bind to. | 
					
						
							|  |  |  |           <literal>null</literal> means "all interfaces". | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |         example = "192.0.2.1"; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       unixSocket = mkOption { | 
					
						
							| 
									
										
										
										
											2014-05-02 20:49:31 +02:00
										 |  |  |         type = with types; nullOr path; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |         default = null; | 
					
						
							| 
									
										
										
										
											2014-06-24 21:23:14 +02:00
										 |  |  |         description = "The path to the socket to bind to."; | 
					
						
							| 
									
										
										
										
											2019-08-31 20:08:49 +02:00
										 |  |  |         example = "/run/redis/redis.sock"; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-24 13:13:47 +03:00
										 |  |  |       unixSocketPerm = mkOption { | 
					
						
							|  |  |  |         type = types.int; | 
					
						
							|  |  |  |         default = 750; | 
					
						
							|  |  |  |         description = "Change permissions for the socket"; | 
					
						
							|  |  |  |         example = 700; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |       logLevel = mkOption { | 
					
						
							| 
									
										
										
										
											2014-05-02 20:49:31 +02:00
										 |  |  |         type = types.str; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |         default = "notice"; # debug, verbose, notice, warning | 
					
						
							|  |  |  |         example = "debug"; | 
					
						
							| 
									
										
										
										
											2014-06-24 21:23:14 +02:00
										 |  |  |         description = "Specify the server verbosity level, options: debug, verbose, notice, warning."; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       logfile = mkOption { | 
					
						
							| 
									
										
										
										
											2014-05-02 20:49:31 +02:00
										 |  |  |         type = types.str; | 
					
						
							| 
									
										
										
										
											2013-10-28 18:14:49 +01:00
										 |  |  |         default = "/dev/null"; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |         description = "Specify the log file name. Also 'stdout' can be used to force Redis to log on the standard output."; | 
					
						
							|  |  |  |         example = "/var/log/redis.log"; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-28 18:14:49 +01:00
										 |  |  |       syslog = mkOption { | 
					
						
							| 
									
										
										
										
											2014-05-02 20:49:31 +02:00
										 |  |  |         type = types.bool; | 
					
						
							| 
									
										
										
										
											2013-10-28 18:14:49 +01:00
										 |  |  |         default = true; | 
					
						
							|  |  |  |         description = "Enable logging to the system logger."; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |       databases = mkOption { | 
					
						
							| 
									
										
										
										
											2014-05-02 20:49:31 +02:00
										 |  |  |         type = types.int; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |         default = 16; | 
					
						
							|  |  |  |         description = "Set the number of databases."; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-12 12:36:28 +03:00
										 |  |  |       maxclients = mkOption { | 
					
						
							|  |  |  |         type = types.int; | 
					
						
							|  |  |  |         default = 10000; | 
					
						
							|  |  |  |         description = "Set the max number of connected clients at the same time."; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |       save = mkOption { | 
					
						
							| 
									
										
										
										
											2014-07-15 17:03:10 +02:00
										 |  |  |         type = with types; listOf (listOf int); | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |         default = [ [900 1] [300 10] [60 10000] ]; | 
					
						
							|  |  |  |         description = "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."; | 
					
						
							|  |  |  |         example = [ [900 1] [300 10] [60 10000] ]; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       slaveOf = mkOption { | 
					
						
							| 
									
										
										
										
											2019-12-30 00:06:23 +01:00
										 |  |  |         type = with types; nullOr (submodule ({ ... }: { | 
					
						
							|  |  |  |           options = { | 
					
						
							|  |  |  |             ip = mkOption { | 
					
						
							|  |  |  |               type = str; | 
					
						
							|  |  |  |               description = "IP of the Redis master"; | 
					
						
							|  |  |  |               example = "192.168.1.100"; | 
					
						
							|  |  |  |             }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             port = mkOption { | 
					
						
							|  |  |  |               type = port; | 
					
						
							|  |  |  |               description = "port of the Redis master"; | 
					
						
							|  |  |  |               default = 6379; | 
					
						
							|  |  |  |             }; | 
					
						
							|  |  |  |           }; | 
					
						
							|  |  |  |         })); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         default = null; | 
					
						
							|  |  |  |         description = "IP and port to which this redis instance acts as a slave."; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |         example = { ip = "192.168.1.100"; port = 6379; }; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       masterAuth = mkOption { | 
					
						
							| 
									
										
										
										
											2021-01-15 03:21:27 +01:00
										 |  |  |         type = with types; nullOr str; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |         default = null; | 
					
						
							|  |  |  |         description = ''If the master is password protected (using the requirePass configuration)
 | 
					
						
							|  |  |  |         it is possible to tell the slave to authenticate before starting the replication synchronization | 
					
						
							| 
									
										
										
										
											2013-07-02 06:03:52 +02:00
										 |  |  |         process, otherwise the master will refuse the slave request. | 
					
						
							|  |  |  |         (STORED PLAIN TEXT, WORLD-READABLE IN NIX STORE)'';
 | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       requirePass = mkOption { | 
					
						
							| 
									
										
										
										
											2014-05-02 20:49:31 +02:00
										 |  |  |         type = with types; nullOr str; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |         default = null; | 
					
						
							| 
									
										
										
										
											2020-02-13 15:56:29 +00:00
										 |  |  |         description = ''
 | 
					
						
							|  |  |  |           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. | 
					
						
							|  |  |  |         '';
 | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |         example = "letmein!"; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-13 15:56:29 +00:00
										 |  |  |       requirePassFile = mkOption { | 
					
						
							|  |  |  |         type = with types; nullOr path; | 
					
						
							|  |  |  |         default = null; | 
					
						
							|  |  |  |         description = "File with password for the database."; | 
					
						
							|  |  |  |         example = "/run/keys/redis-password"; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |       appendOnly = mkOption { | 
					
						
							| 
									
										
										
										
											2014-05-02 20:49:31 +02:00
										 |  |  |         type = types.bool; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |         default = false; | 
					
						
							|  |  |  |         description = "By default data is only periodically persisted to disk, enable this option to use an append-only file for improved persistence."; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       appendFsync = mkOption { | 
					
						
							| 
									
										
										
										
											2014-05-02 20:49:31 +02:00
										 |  |  |         type = types.str; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |         default = "everysec"; # no, always, everysec | 
					
						
							| 
									
										
										
										
											2014-06-24 21:23:14 +02:00
										 |  |  |         description = "How often to fsync the append-only log, options: no, always, everysec."; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       slowLogLogSlowerThan = mkOption { | 
					
						
							| 
									
										
										
										
											2014-05-02 20:49:31 +02:00
										 |  |  |         type = types.int; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |         default = 10000; | 
					
						
							| 
									
										
										
										
											2014-06-24 21:23:14 +02:00
										 |  |  |         description = "Log queries whose execution take longer than X in milliseconds."; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |         example = 1000; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       slowLogMaxLen = mkOption { | 
					
						
							| 
									
										
										
										
											2014-05-02 20:49:31 +02:00
										 |  |  |         type = types.int; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |         default = 128; | 
					
						
							| 
									
										
										
										
											2014-06-24 21:23:14 +02:00
										 |  |  |         description = "Maximum number of items to keep in slow log."; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |       }; | 
					
						
							| 
									
										
										
										
											2013-06-17 14:06:02 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-04 19:47:32 -05:00
										 |  |  |       settings = mkOption { | 
					
						
							|  |  |  |         type = with types; attrsOf (oneOf [ bool int str (listOf str) ]); | 
					
						
							|  |  |  |         default = {}; | 
					
						
							|  |  |  |         description = ''
 | 
					
						
							|  |  |  |           Redis configuration. Refer to | 
					
						
							|  |  |  |           <link xlink:href="https://redis.io/topics/config"/> | 
					
						
							|  |  |  |           for details on supported values. | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |         example = literalExample ''
 | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             loadmodule = [ "/path/to/my_module.so" "/path/to/other_module.so" ]; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         '';
 | 
					
						
							| 
									
										
										
										
											2013-06-17 14:06:02 -04:00
										 |  |  |       }; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ###### implementation | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   config = mkIf config.services.redis.enable { | 
					
						
							| 
									
										
										
										
											2020-02-13 15:56:29 +00:00
										 |  |  |     assertions = [{ | 
					
						
							|  |  |  |       assertion = cfg.requirePass != null -> cfg.requirePassFile == null; | 
					
						
							|  |  |  |       message = "You can only set one services.redis.requirePass or services.redis.requirePassFile"; | 
					
						
							|  |  |  |     }]; | 
					
						
							| 
									
										
										
										
											2019-11-08 15:37:30 +01:00
										 |  |  |     boot.kernel.sysctl = (mkMerge [ | 
					
						
							|  |  |  |       { "vm.nr_hugepages" = "0"; } | 
					
						
							|  |  |  |       ( mkIf cfg.vmOverCommit { "vm.overcommit_memory" = "1"; } ) | 
					
						
							|  |  |  |     ]); | 
					
						
							| 
									
										
										
										
											2015-10-02 23:22:27 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     networking.firewall = mkIf cfg.openFirewall { | 
					
						
							|  |  |  |       allowedTCPPorts = [ cfg.port ]; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-12 22:25:28 +02:00
										 |  |  |     users.users.redis = { | 
					
						
							|  |  |  |       description = "Redis database user"; | 
					
						
							|  |  |  |       isSystemUser = true; | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2020-06-08 16:09:13 +01:00
										 |  |  |     users.groups.redis = {}; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-07 11:37:58 +02:00
										 |  |  |     environment.systemPackages = [ cfg.package ]; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-04 19:47:32 -05:00
										 |  |  |     services.redis.settings = mkMerge [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         port = cfg.port; | 
					
						
							|  |  |  |         daemonize = false; | 
					
						
							|  |  |  |         supervised = "systemd"; | 
					
						
							|  |  |  |         loglevel = cfg.logLevel; | 
					
						
							|  |  |  |         logfile = cfg.logfile; | 
					
						
							|  |  |  |         syslog-enabled = cfg.syslog; | 
					
						
							|  |  |  |         databases = cfg.databases; | 
					
						
							| 
									
										
										
										
											2021-04-12 12:36:28 +03:00
										 |  |  |         maxclients = cfg.maxclients; | 
					
						
							| 
									
										
										
										
											2021-01-04 19:47:32 -05:00
										 |  |  |         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; }) | 
					
						
							| 
									
										
										
										
											2021-03-24 13:13:47 +03:00
										 |  |  |       (mkIf (cfg.unixSocket != null) { unixsocket = cfg.unixSocket; unixsocketperm = "${toString cfg.unixSocketPerm}"; }) | 
					
						
							| 
									
										
										
										
											2021-01-04 19:47:32 -05:00
										 |  |  |       (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; }) | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-13 15:56:29 +00:00
										 |  |  |     systemd.services.redis = { | 
					
						
							|  |  |  |       description = "Redis Server"; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-13 15:56:29 +00:00
										 |  |  |       wantedBy = [ "multi-user.target" ]; | 
					
						
							|  |  |  |       after = [ "network.target" ]; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-13 15:56:29 +00:00
										 |  |  |       preStart = ''
 | 
					
						
							|  |  |  |         install -m 600 ${redisConfig} /run/redis/redis.conf | 
					
						
							|  |  |  |       '' + optionalString (cfg.requirePassFile != null) '' | 
					
						
							|  |  |  |         password=$(cat ${escapeShellArg cfg.requirePassFile}) | 
					
						
							|  |  |  |         echo "requirePass $password" >> /run/redis/redis.conf | 
					
						
							|  |  |  |       '';
 | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-13 15:56:29 +00:00
										 |  |  |       serviceConfig = { | 
					
						
							|  |  |  |         ExecStart = "${cfg.package}/bin/redis-server /run/redis/redis.conf"; | 
					
						
							|  |  |  |         Type = "notify"; | 
					
						
							| 
									
										
										
										
											2021-03-24 13:33:34 +03:00
										 |  |  |         # User and group | 
					
						
							| 
									
										
										
										
											2020-02-13 15:56:29 +00:00
										 |  |  |         User = "redis"; | 
					
						
							| 
									
										
										
										
											2020-06-08 16:09:13 +01:00
										 |  |  |         Group = "redis"; | 
					
						
							| 
									
										
										
										
											2021-03-24 13:33:34 +03:00
										 |  |  |         # Runtime directory and mode | 
					
						
							|  |  |  |         RuntimeDirectory = "redis"; | 
					
						
							|  |  |  |         RuntimeDirectoryMode = "0750"; | 
					
						
							|  |  |  |         # State directory and mode | 
					
						
							|  |  |  |         StateDirectory = "redis"; | 
					
						
							|  |  |  |         StateDirectoryMode = "0700"; | 
					
						
							|  |  |  |         # Access write directories | 
					
						
							|  |  |  |         UMask = "0077"; | 
					
						
							| 
									
										
										
										
											2021-04-03 23:00:48 +03:00
										 |  |  |         # Capabilities | 
					
						
							|  |  |  |         CapabilityBoundingSet = ""; | 
					
						
							|  |  |  |         # Security | 
					
						
							|  |  |  |         NoNewPrivileges = true; | 
					
						
							| 
									
										
										
										
											2021-04-12 12:36:28 +03:00
										 |  |  |         # Process Properties | 
					
						
							|  |  |  |         LimitNOFILE = "${toString ulimitNofile}"; | 
					
						
							| 
									
										
										
										
											2021-04-03 23:00:48 +03:00
										 |  |  |         # Sandboxing | 
					
						
							|  |  |  |         ProtectSystem = "strict"; | 
					
						
							|  |  |  |         ProtectHome = true; | 
					
						
							|  |  |  |         PrivateTmp = true; | 
					
						
							|  |  |  |         PrivateDevices = true; | 
					
						
							|  |  |  |         PrivateUsers = true; | 
					
						
							|  |  |  |         ProtectClock = true; | 
					
						
							|  |  |  |         ProtectHostname = true; | 
					
						
							|  |  |  |         ProtectKernelLogs = true; | 
					
						
							|  |  |  |         ProtectKernelModules = true; | 
					
						
							|  |  |  |         ProtectKernelTunables = true; | 
					
						
							|  |  |  |         ProtectControlGroups = true; | 
					
						
							|  |  |  |         RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ]; | 
					
						
							|  |  |  |         RestrictNamespaces = true; | 
					
						
							|  |  |  |         LockPersonality = true; | 
					
						
							|  |  |  |         MemoryDenyWriteExecute = true; | 
					
						
							|  |  |  |         RestrictRealtime = true; | 
					
						
							|  |  |  |         RestrictSUIDSGID = true; | 
					
						
							|  |  |  |         PrivateMounts = true; | 
					
						
							|  |  |  |         # System Call Filtering | 
					
						
							|  |  |  |         SystemCallArchitectures = "native"; | 
					
						
							|  |  |  |         SystemCallFilter = "~@clock @cpu-emulation @debug @keyring @memlock @module @mount @obsolete @privileged @raw-io @reboot @resources @setuid @swap"; | 
					
						
							| 
									
										
										
										
											2020-02-13 15:56:29 +00:00
										 |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2013-06-07 11:34:05 +02:00
										 |  |  |   }; | 
					
						
							|  |  |  | } |