mirror of
https://github.com/juspay/services-flake.git
synced 2024-09-11 12:26:04 +03:00
**PR description** - The user can now set `namespace` for the processes under each service - Default namespace is now `${service}.${name}` (previously, just `${name}`) **Tasks** - [x] Do this for postgres, to begin with. - [x] Rest of the services ![image](https://github.com/juspay/services-flake/assets/3998/9ffea918-6481-42ad-ac47-cb5c1c81bd92) After the user overrides it: <img width="460" alt="image" src="https://github.com/juspay/services-flake/assets/3998/da6fb51e-e39f-4c33-bb47-e6b7cfd8c2b5"> After the user overrides the local processes as well: <img width="460" alt="image" src="https://github.com/juspay/services-flake/assets/3998/ae493309-4449-4cde-b239-c6e234b9f8af">
93 lines
2.4 KiB
Nix
93 lines
2.4 KiB
Nix
# Based on https://github.com/cachix/devenv/blob/main/src/modules/services/redis.nix
|
|
{ pkgs, lib, name, config, ... }:
|
|
let
|
|
inherit (lib) types;
|
|
in
|
|
{
|
|
options = {
|
|
enable = lib.mkEnableOption name;
|
|
|
|
package = lib.mkPackageOption pkgs "redis" { };
|
|
|
|
dataDir = lib.mkOption {
|
|
type = types.str;
|
|
default = "./data/${name}";
|
|
description = "The redis data directory";
|
|
};
|
|
|
|
bind = lib.mkOption {
|
|
type = types.nullOr types.str;
|
|
default = "127.0.0.1";
|
|
description = ''
|
|
The IP interface to bind to.
|
|
`null` means "all interfaces".
|
|
'';
|
|
example = "127.0.0.1";
|
|
};
|
|
|
|
port = lib.mkOption {
|
|
type = types.port;
|
|
default = 6379;
|
|
description = ''
|
|
The TCP port to accept connections.
|
|
|
|
If port is set to `0`, redis will not listen on a TCP socket.
|
|
'';
|
|
};
|
|
|
|
extraConfig = lib.mkOption {
|
|
type = types.lines;
|
|
default = "";
|
|
description = "Additional text to be appended to `redis.conf`.";
|
|
};
|
|
};
|
|
|
|
config = {
|
|
outputs = {
|
|
settings = {
|
|
processes = {
|
|
"${name}" =
|
|
let
|
|
redisConfig = pkgs.writeText "redis.conf" ''
|
|
port ${toString config.port}
|
|
${lib.optionalString (config.bind != null) "bind ${config.bind}"}
|
|
${config.extraConfig}
|
|
'';
|
|
|
|
startScript = pkgs.writeShellApplication {
|
|
name = "start-redis";
|
|
runtimeInputs = [ pkgs.coreutils config.package ];
|
|
text = ''
|
|
set -euo pipefail
|
|
|
|
export REDISDATA=${config.dataDir}
|
|
|
|
if [[ ! -d "$REDISDATA" ]]; then
|
|
mkdir -p "$REDISDATA"
|
|
fi
|
|
|
|
exec redis-server ${redisConfig} --dir "$REDISDATA"
|
|
'';
|
|
};
|
|
in
|
|
{
|
|
command = startScript;
|
|
|
|
readiness_probe = {
|
|
exec.command = "${config.package}/bin/redis-cli -p ${toString config.port} ping";
|
|
initial_delay_seconds = 2;
|
|
period_seconds = 10;
|
|
timeout_seconds = 4;
|
|
success_threshold = 1;
|
|
failure_threshold = 5;
|
|
};
|
|
|
|
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
|
|
availability.restart = "on_failure";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
}
|