nixos/services.memcached: remove with lib;

This commit is contained in:
Felix Buehler
2024-12-08 13:21:51 +01:00
parent 3aa36dd181
commit 261e4890fb
+19 -22
View File
@@ -1,7 +1,4 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.memcached;
@@ -17,42 +14,42 @@ in
options = {
services.memcached = {
enable = mkEnableOption "Memcached";
enable = lib.mkEnableOption "Memcached";
user = mkOption {
type = types.str;
user = lib.mkOption {
type = lib.types.str;
default = "memcached";
description = "The user to run Memcached as";
};
listen = mkOption {
type = types.str;
listen = lib.mkOption {
type = lib.types.str;
default = "127.0.0.1";
description = "The IP address to bind to.";
};
port = mkOption {
type = types.port;
port = lib.mkOption {
type = lib.types.port;
default = 11211;
description = "The port to bind to.";
};
enableUnixSocket = mkEnableOption "Unix Domain Socket at /run/memcached/memcached.sock instead of listening on an IP address and port. The `listen` and `port` options are ignored";
enableUnixSocket = lib.mkEnableOption "Unix Domain Socket at /run/memcached/memcached.sock instead of listening on an IP address and port. The `listen` and `port` options are ignored";
maxMemory = mkOption {
type = types.ints.unsigned;
maxMemory = lib.mkOption {
type = lib.types.ints.unsigned;
default = 64;
description = "The maximum amount of memory to use for storage, in megabytes.";
};
maxConnections = mkOption {
type = types.ints.unsigned;
maxConnections = lib.mkOption {
type = lib.types.ints.unsigned;
default = 1024;
description = "The maximum number of simultaneous connections.";
};
extraOptions = mkOption {
type = types.listOf types.str;
extraOptions = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [];
description = "A list of extra options that will be added as a suffix when running memcached.";
};
@@ -62,14 +59,14 @@ in
###### implementation
config = mkIf config.services.memcached.enable {
config = lib.mkIf config.services.memcached.enable {
users.users = optionalAttrs (cfg.user == "memcached") {
users.users = lib.optionalAttrs (cfg.user == "memcached") {
memcached.description = "Memcached server user";
memcached.isSystemUser = true;
memcached.group = "memcached";
};
users.groups = optionalAttrs (cfg.user == "memcached") { memcached = {}; };
users.groups = lib.optionalAttrs (cfg.user == "memcached") { memcached = {}; };
environment.systemPackages = [ memcached ];
@@ -85,7 +82,7 @@ in
networking = if cfg.enableUnixSocket
then "-s /run/memcached/memcached.sock"
else "-l ${cfg.listen} -p ${toString cfg.port}";
in "${memcached}/bin/memcached ${networking} -m ${toString cfg.maxMemory} -c ${toString cfg.maxConnections} ${concatStringsSep " " cfg.extraOptions}";
in "${memcached}/bin/memcached ${networking} -m ${toString cfg.maxMemory} -c ${toString cfg.maxConnections} ${lib.concatStringsSep " " cfg.extraOptions}";
User = cfg.user;
@@ -110,7 +107,7 @@ in
};
};
imports = [
(mkRemovedOptionModule ["services" "memcached" "socket"] ''
(lib.mkRemovedOptionModule ["services" "memcached" "socket"] ''
This option was replaced by a fixed unix socket path at /run/memcached/memcached.sock enabled using services.memcached.enableUnixSocket.
'')
];