summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaiderd Jordan <daiderd@gmail.com>2017-09-07 22:39:35 +0200
committerDaiderd Jordan <daiderd@gmail.com>2017-09-07 22:39:35 +0200
commit6fa180702b4a95f40df3abd7332e003f8051bd8e (patch)
tree3ca8bfb18fb8d8868b30bfd5c4723ab7a2e68c8e
parent9f0507cf7d62472650bb3f2d936d0d43ef6009b4 (diff)
modules: add redis service
-rw-r--r--default.nix5
-rw-r--r--modules/services/redis/default.nix75
2 files changed, 78 insertions, 2 deletions
diff --git a/default.nix b/default.nix
index a7a175b..477e232 100644
--- a/default.nix
+++ b/default.nix
@@ -40,14 +40,15 @@ let
./modules/launchd
./modules/security
./modules/services/activate-system
- ./modules/services/khd
- ./modules/services/kwm
./modules/services/chunkwm.nix
./modules/services/emacs.nix
+ ./modules/services/khd
+ ./modules/services/kwm
./modules/services/mopidy.nix
./modules/services/nix-daemon.nix
./modules/services/nix-gc
./modules/services/postgresql
+ ./modules/services/redis
./modules/programs/bash.nix
./modules/programs/fish.nix
./modules/programs/man.nix
diff --git a/modules/services/redis/default.nix b/modules/services/redis/default.nix
new file mode 100644
index 0000000..860ebc1
--- /dev/null
+++ b/modules/services/redis/default.nix
@@ -0,0 +1,75 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+ cfg = config.services.redis;
+in
+
+{
+ options = {
+ services.redis.enable = mkOption {
+ type = types.bool;
+ default = false;
+ description = "Whether to enable the redis database service.";
+ };
+
+ services.redis.package = mkOption {
+ type = types.path;
+ default = pkgs.redis;
+ defaultText = "pkgs.redis";
+ description = "This option specifies the redis package to use";
+ };
+
+ services.redis.dataDir = mkOption {
+ type = types.path;
+ default = "/var/lib/redis";
+ description = "Data directory for the redis database.";
+ };
+
+ services.redis.port = mkOption {
+ type = types.int;
+ default = 6379;
+ description = "The port for Redis to listen to.";
+ };
+
+ services.redis.bind = mkOption {
+ type = types.nullOr types.str;
+ default = null; # All interfaces
+ description = "The IP interface to bind to.";
+ example = "127.0.0.1";
+ };
+
+ services.redis.unixSocket = mkOption {
+ type = types.nullOr types.path;
+ default = null;
+ description = "The path to the socket to bind to.";
+ example = "/var/run/redis.sock";
+ };
+
+ services.redis.appendOnly = mkOption {
+ type = types.bool;
+ default = false;
+ description = "By default data is only periodically persisted to disk, enable this option to use an append-only file for improved persistence.";
+ };
+ };
+
+ config = mkIf cfg.enable {
+
+ environment.systemPackages = [ cfg.package ];
+
+ launchd.user.agents.redis = {
+ command = "${cfg.package}/bin/redis-server /etc/redis.conf";
+ serviceConfig.KeepAlive = true;
+ };
+
+ environment.etc."redis.conf".text = ''
+ port ${toString cfg.port}
+ ${optionalString (cfg.bind != null) "bind ${cfg.bind}"}
+ ${optionalString (cfg.unixSocket != null) "unixsocket ${cfg.unixSocket}"}
+ dir ${cfg.dataDir}
+ appendOnly ${if cfg.appendOnly then "yes" else "no"}
+ '';
+
+ };
+}