Merge pull request #185 from ocharles/memcached

memcached: Add NixOS support
This commit is contained in:
Peter Simons 2013-07-01 03:00:45 -07:00
commit ff8a01b145
2 changed files with 98 additions and 0 deletions

View file

@ -74,6 +74,7 @@
./services/backup/sitecopy-backup.nix
./services/databases/4store-endpoint.nix
./services/databases/4store.nix
./services/databases/memcached.nix
./services/databases/mongodb.nix
./services/databases/redis.nix
./services/databases/mysql.nix

View file

@ -0,0 +1,97 @@
{ config, pkgs, ... }:
with pkgs.lib;
let
cfg = config.services.memcached;
memcached = pkgs.memcached;
in
{
###### interface
options = {
services.memcached = {
enable = mkOption {
default = false;
description = "
Whether to enable Memcached.
";
};
user = mkOption {
default = "memcached";
description = "The user to run Memcached as";
};
listen = mkOption {
default = "127.0.0.1";
description = "The IP address to bind to";
};
port = mkOption {
default = 11211;
description = "The port to bind to";
};
socket = mkOption {
default = "";
description = "Unix socket path to listen on. Setting this will disable network support";
example = "/var/run/memcached";
};
maxMemory = mkOption {
default = 64;
description = "The maximum amount of memory to use for storage, in megabytes.";
};
maxConnections = mkOption {
default = 1024;
description = "The maximum number of simultaneous connections";
};
extraOptions = mkOption {
default = [];
description = "A list of extra options that will be added as a suffix when running memcached";
};
};
};
###### implementation
config = mkIf config.services.memcached.enable {
users.extraUsers = singleton
{ name = cfg.user;
description = "Memcached server user";
};
environment.systemPackages = [ memcached ];
systemd.services.memcached =
{ description = "Memcached server";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
ExecStart =
let
networking = if cfg.socket != ""
then "-s ${cfg.socket}"
else "-l ${cfg.listen} -p ${toString cfg.port}";
in "${memcached}/bin/memcached ${networking} -m ${toString cfg.maxMemory} -c ${toString cfg.maxConnections} ${concatStringsSep " " cfg.extraOptions}";
User = cfg.user;
};
};
};
}