1
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-19 07:59:24 +03:00
nixpkgs/nixos/modules/services/databases/dragonflydb.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

159 lines
4.5 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.dragonflydb;
dragonflydb = pkgs.dragonflydb;
settings =
{
port = cfg.port;
dir = "/var/lib/dragonflydb";
keys_output_limit = cfg.keysOutputLimit;
}
// (lib.optionalAttrs (cfg.bind != null) { bind = cfg.bind; })
// (lib.optionalAttrs (cfg.requirePass != null) { requirepass = cfg.requirePass; })
// (lib.optionalAttrs (cfg.maxMemory != null) { maxmemory = cfg.maxMemory; })
// (lib.optionalAttrs (cfg.memcachePort != null) { memcache_port = cfg.memcachePort; })
// (lib.optionalAttrs (cfg.dbNum != null) { dbnum = cfg.dbNum; })
// (lib.optionalAttrs (cfg.cacheMode != null) { cache_mode = cfg.cacheMode; });
in
{
###### interface
options = {
services.dragonflydb = {
enable = lib.mkEnableOption "DragonflyDB";
user = lib.mkOption {
type = lib.types.str;
default = "dragonfly";
description = "The user to run DragonflyDB as";
};
port = lib.mkOption {
type = lib.types.port;
default = 6379;
description = "The TCP port to accept connections.";
};
bind = lib.mkOption {
type = with lib.types; nullOr str;
default = "127.0.0.1";
description = ''
The IP interface to bind to.
`null` means "all interfaces".
'';
};
requirePass = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
description = "Password for database";
example = "letmein!";
};
maxMemory = lib.mkOption {
type = with lib.types; nullOr ints.unsigned;
default = null;
description = ''
The maximum amount of memory to use for storage (in bytes).
`null` means this will be automatically set.
'';
};
memcachePort = lib.mkOption {
type = with lib.types; nullOr port;
default = null;
description = ''
To enable memcached compatible API on this port.
`null` means disabled.
'';
};
keysOutputLimit = lib.mkOption {
type = lib.types.ints.unsigned;
default = 8192;
description = ''
Maximum number of returned keys in keys command.
`keys` is a dangerous command.
We truncate its result to avoid blowup in memory when fetching too many keys.
'';
};
dbNum = lib.mkOption {
type = with lib.types; nullOr ints.unsigned;
default = null;
description = "Maximum number of supported databases for `select`";
};
cacheMode = lib.mkOption {
type = with lib.types; nullOr bool;
default = null;
description = ''
Once this mode is on, Dragonfly will evict items least likely to be stumbled
upon in the future but only when it is near maxmemory limit.
'';
};
};
};
###### implementation
config = lib.mkIf config.services.dragonflydb.enable {
users.users = lib.optionalAttrs (cfg.user == "dragonfly") {
dragonfly.description = "DragonflyDB server user";
dragonfly.isSystemUser = true;
dragonfly.group = "dragonfly";
};
users.groups = lib.optionalAttrs (cfg.user == "dragonfly") { dragonfly = { }; };
environment.systemPackages = [ dragonflydb ];
systemd.services.dragonflydb = {
description = "DragonflyDB server";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
ExecStart = "${dragonflydb}/bin/dragonfly --alsologtostderr ${
lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "--${n} ${lib.escapeShellArg v}") settings)
}";
User = cfg.user;
# Filesystem access
ReadWritePaths = [ settings.dir ];
StateDirectory = "dragonflydb";
StateDirectoryMode = "0700";
# Process Properties
LimitMEMLOCK = "infinity";
# Caps
CapabilityBoundingSet = "";
NoNewPrivileges = true;
# Sandboxing
ProtectSystem = "strict";
ProtectHome = true;
PrivateTmp = true;
PrivateDevices = true;
ProtectKernelTunables = true;
ProtectKernelModules = true;
ProtectControlGroups = true;
LockPersonality = true;
RestrictAddressFamilies = [
"AF_INET"
"AF_INET6"
];
RestrictRealtime = true;
PrivateMounts = true;
MemoryDenyWriteExecute = true;
};
};
};
}