mirror of
https://github.com/juspay/services-flake.git
synced 2024-10-05 16:37:38 +03:00
feat: Allow overriding namespace + make default namespace fully qualified (#258)
**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">
This commit is contained in:
parent
b713baa32b
commit
d6d9cf2de1
@ -152,12 +152,10 @@ with lib;
|
||||
defaultText = literalExpression "pkgs.apacheKafka.passthru.jre";
|
||||
type = types.package;
|
||||
};
|
||||
|
||||
outputs.settings = lib.mkOption {
|
||||
type = types.deferredModule;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = {
|
||||
};
|
||||
config = {
|
||||
outputs = {
|
||||
settings = {
|
||||
processes = {
|
||||
"${name}" =
|
||||
let
|
||||
@ -186,7 +184,6 @@ with lib;
|
||||
success_threshold = 1;
|
||||
failure_threshold = 5;
|
||||
};
|
||||
namespace = name;
|
||||
|
||||
availability.restart = "on_failure";
|
||||
};
|
||||
|
@ -92,12 +92,11 @@ in
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
outputs.settings = lib.mkOption {
|
||||
type = types.deferredModule;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = {
|
||||
config = {
|
||||
outputs = {
|
||||
settings = {
|
||||
processes = {
|
||||
"${name}" =
|
||||
let
|
||||
@ -161,7 +160,6 @@ in
|
||||
success_threshold = 1;
|
||||
failure_threshold = 5;
|
||||
};
|
||||
namespace = name;
|
||||
|
||||
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
|
||||
availability.restart = "on_failure";
|
||||
|
@ -89,11 +89,10 @@ in
|
||||
]
|
||||
'';
|
||||
};
|
||||
outputs.settings = lib.mkOption {
|
||||
type = types.deferredModule;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = {
|
||||
};
|
||||
config = {
|
||||
outputs = {
|
||||
settings = {
|
||||
processes =
|
||||
let
|
||||
clickhouseConfig = yamlFormat.generate "clickhouse-config.yaml" (
|
||||
@ -139,7 +138,6 @@ in
|
||||
in
|
||||
{
|
||||
command = setupScript;
|
||||
namespace = name;
|
||||
};
|
||||
|
||||
# DB process
|
||||
@ -170,7 +168,6 @@ in
|
||||
success_threshold = 1;
|
||||
failure_threshold = 5;
|
||||
};
|
||||
namespace = name;
|
||||
depends_on."${name}-init".condition = "process_completed_successfully";
|
||||
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
|
||||
availability.restart = "on_failure";
|
||||
|
@ -105,12 +105,11 @@ in
|
||||
example =
|
||||
lib.literalExpression "[ pkgs.elasticsearchPlugins.discovery-ec2 ]";
|
||||
};
|
||||
};
|
||||
|
||||
outputs.settings = lib.mkOption {
|
||||
type = types.deferredModule;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = {
|
||||
config = {
|
||||
outputs = {
|
||||
settings = {
|
||||
processes."${name}" =
|
||||
let
|
||||
es7 = builtins.compareVersions config.package.version "7" >= 0;
|
||||
@ -197,7 +196,6 @@ in
|
||||
success_threshold = 1;
|
||||
failure_threshold = 5;
|
||||
};
|
||||
namespace = name;
|
||||
|
||||
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
|
||||
availability.restart = "on_failure";
|
||||
|
@ -100,12 +100,11 @@ in
|
||||
]
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
outputs.settings = lib.mkOption {
|
||||
type = types.deferredModule;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = {
|
||||
config = {
|
||||
outputs = {
|
||||
settings = {
|
||||
processes."${name}" =
|
||||
let
|
||||
grafanaConfig = lib.recursiveUpdate
|
||||
@ -168,7 +167,6 @@ in
|
||||
success_threshold = 1;
|
||||
failure_threshold = 5;
|
||||
};
|
||||
namespace = name;
|
||||
|
||||
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
|
||||
availability.restart = "on_failure";
|
||||
|
47
nix/lib.nix
47
nix/lib.nix
@ -8,25 +8,62 @@
|
||||
{ config, pkgs, lib, ... }:
|
||||
let
|
||||
# Derive name from filename
|
||||
name = lib.pipe mod [
|
||||
service = lib.pipe mod [
|
||||
builtins.baseNameOf
|
||||
(lib.strings.splitString ".")
|
||||
builtins.head
|
||||
];
|
||||
serviceModule = { config, name, ... }: {
|
||||
options = {
|
||||
namespace = lib.mkOption {
|
||||
description = ''
|
||||
Namespace for the ${service} service
|
||||
'';
|
||||
default = "${service}.${name}";
|
||||
type = lib.types.str;
|
||||
};
|
||||
outputs.defaultProcessSettings = lib.mkOption {
|
||||
type = lib.types.deferredModule;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
description = ''
|
||||
Default settings for all processes under the ${service} service
|
||||
'';
|
||||
default = {
|
||||
namespace = lib.mkDefault config.namespace;
|
||||
};
|
||||
};
|
||||
outputs.settings = lib.mkOption {
|
||||
type = lib.types.lazyAttrsOf lib.types.raw;
|
||||
internal = true;
|
||||
description = ''
|
||||
process-compose settings for the processes under the ${service} service
|
||||
'';
|
||||
apply = v: v // {
|
||||
processes = lib.flip lib.mapAttrs v.processes (_: cfg:
|
||||
{ imports = [ config.outputs.defaultProcessSettings cfg ]; }
|
||||
);
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
options.services.${name} = lib.mkOption {
|
||||
options.services.${service} = lib.mkOption {
|
||||
description = ''
|
||||
${name} service
|
||||
${service} service
|
||||
'';
|
||||
default = { };
|
||||
type = lib.types.attrsOf (lib.types.submoduleWith {
|
||||
specialArgs = { inherit pkgs; };
|
||||
modules = [ mod ];
|
||||
modules = [
|
||||
serviceModule
|
||||
mod
|
||||
];
|
||||
});
|
||||
};
|
||||
config.settings.imports =
|
||||
lib.pipe config.services.${name} [
|
||||
lib.pipe config.services.${service} [
|
||||
(lib.filterAttrs (_: cfg: cfg.enable))
|
||||
(lib.mapAttrsToList (_: cfg: cfg.outputs.settings))
|
||||
];
|
||||
|
@ -163,11 +163,11 @@ in
|
||||
]
|
||||
'';
|
||||
};
|
||||
outputs.settings = lib.mkOption {
|
||||
type = types.deferredModule;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = {
|
||||
};
|
||||
|
||||
config = {
|
||||
outputs = {
|
||||
settings = {
|
||||
processes =
|
||||
let
|
||||
isMariaDB = lib.getName config.package == lib.getName pkgs.mariadb;
|
||||
@ -298,14 +298,12 @@ in
|
||||
success_threshold = 1;
|
||||
failure_threshold = 5;
|
||||
};
|
||||
namespace = name;
|
||||
|
||||
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
|
||||
availability.restart = "on_failure";
|
||||
};
|
||||
"${name}-configure" = {
|
||||
command = configureScript;
|
||||
namespace = name;
|
||||
depends_on."${name}".condition = "process_healthy";
|
||||
};
|
||||
};
|
||||
|
@ -86,11 +86,10 @@ in
|
||||
description = "The nginx configuration file.";
|
||||
};
|
||||
|
||||
outputs.settings = lib.mkOption {
|
||||
type = lib.types.deferredModule;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default =
|
||||
};
|
||||
config = {
|
||||
outputs = {
|
||||
settings.processes =
|
||||
let
|
||||
startScript = pkgs.writeShellApplication {
|
||||
name = "start-nginx";
|
||||
@ -106,7 +105,7 @@ in
|
||||
};
|
||||
in
|
||||
{
|
||||
processes."${name}" = {
|
||||
"${name}" = {
|
||||
command = startScript;
|
||||
readiness_probe = {
|
||||
# FIXME need a better health check
|
||||
@ -117,7 +116,6 @@ in
|
||||
success_threshold = 1;
|
||||
failure_threshold = 5;
|
||||
};
|
||||
namespace = name;
|
||||
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
|
||||
availability.restart = "on_failure";
|
||||
};
|
||||
|
@ -78,12 +78,11 @@ in
|
||||
Extra environment variables passed to the `ollama-server` process.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
outputs.settings = lib.mkOption {
|
||||
type = types.deferredModule;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = {
|
||||
config = {
|
||||
outputs = {
|
||||
settings = {
|
||||
processes = {
|
||||
"${name}" =
|
||||
let
|
||||
@ -119,7 +118,6 @@ in
|
||||
success_threshold = 1;
|
||||
failure_threshold = 5;
|
||||
};
|
||||
namespace = name;
|
||||
availability.restart = "on_failure";
|
||||
};
|
||||
|
||||
@ -137,7 +135,6 @@ in
|
||||
done
|
||||
'';
|
||||
};
|
||||
namespace = name;
|
||||
depends_on."${name}".condition = "process_healthy";
|
||||
};
|
||||
};
|
||||
|
@ -48,12 +48,11 @@ in
|
||||
'';
|
||||
description = "Extra environment variables for Open-WebUI";
|
||||
};
|
||||
};
|
||||
|
||||
outputs.settings = lib.mkOption {
|
||||
type = types.deferredModule;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = {
|
||||
config = {
|
||||
outputs = {
|
||||
settings = {
|
||||
processes = {
|
||||
"${name}" =
|
||||
let
|
||||
@ -97,7 +96,6 @@ in
|
||||
success_threshold = 1;
|
||||
failure_threshold = 5;
|
||||
};
|
||||
namespace = name;
|
||||
availability.restart = "on_failure";
|
||||
};
|
||||
};
|
||||
|
@ -85,12 +85,11 @@ in
|
||||
default = { };
|
||||
description = "Additional config for pgadmin4";
|
||||
};
|
||||
};
|
||||
|
||||
outputs.settings = lib.mkOption {
|
||||
type = types.deferredModule;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = {
|
||||
config = {
|
||||
outputs = {
|
||||
settings = {
|
||||
processes =
|
||||
let
|
||||
pgadminConfig = pkgs.writeTextDir "config_local.py" (
|
||||
@ -129,7 +128,6 @@ in
|
||||
in
|
||||
{
|
||||
command = setupScript;
|
||||
namespace = name;
|
||||
};
|
||||
|
||||
"${name}" =
|
||||
@ -167,7 +165,6 @@ in
|
||||
success_threshold = 1;
|
||||
failure_threshold = 5;
|
||||
};
|
||||
namespace = name;
|
||||
depends_on."${name}-init".condition = "process_completed_successfully";
|
||||
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
|
||||
availability.restart = "on_failure";
|
||||
|
@ -289,11 +289,10 @@ in
|
||||
SQL expressions separated by a semi-colon.
|
||||
'';
|
||||
};
|
||||
outputs.settings = lib.mkOption {
|
||||
type = types.deferredModule;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default =
|
||||
};
|
||||
config = {
|
||||
outputs = {
|
||||
settings =
|
||||
{
|
||||
processes = {
|
||||
# DB initialization
|
||||
@ -303,7 +302,6 @@ in
|
||||
in
|
||||
{
|
||||
command = setupScript;
|
||||
namespace = name;
|
||||
};
|
||||
|
||||
# DB process
|
||||
@ -342,7 +340,6 @@ in
|
||||
success_threshold = 1;
|
||||
failure_threshold = 5;
|
||||
};
|
||||
namespace = name;
|
||||
depends_on."${name}-init".condition = "process_completed_successfully";
|
||||
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
|
||||
availability.restart = "on_failure";
|
||||
|
@ -59,12 +59,11 @@ in
|
||||
}];
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
outputs.settings = lib.mkOption {
|
||||
type = types.deferredModule;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = {
|
||||
config = {
|
||||
outputs = {
|
||||
settings = {
|
||||
processes = {
|
||||
"${name}" =
|
||||
let
|
||||
@ -97,7 +96,6 @@ in
|
||||
success_threshold = 1;
|
||||
failure_threshold = 5;
|
||||
};
|
||||
namespace = name;
|
||||
|
||||
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
|
||||
availability.restart = "on_failure";
|
||||
|
@ -67,12 +67,11 @@ in
|
||||
Number of replicas per Master node.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
outputs.settings = lib.mkOption {
|
||||
type = types.deferredModule;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default =
|
||||
config = {
|
||||
outputs = {
|
||||
settings =
|
||||
let
|
||||
mkNodeProcess = nodeName: cfg:
|
||||
let
|
||||
@ -118,7 +117,6 @@ in
|
||||
success_threshold = 1;
|
||||
failure_threshold = 5;
|
||||
};
|
||||
namespace = name;
|
||||
|
||||
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
|
||||
availability.restart = "on_failure";
|
||||
@ -147,7 +145,6 @@ in
|
||||
"${name}-cluster-create" = {
|
||||
depends_on = lib.mapAttrs' (nodeName: cfg: lib.nameValuePair "${name}-${nodeName}" { condition = "process_healthy"; }) config.nodes;
|
||||
command = lib.getExe clusterCreateScript;
|
||||
namespace = name;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -40,12 +40,11 @@ in
|
||||
default = "";
|
||||
description = "Additional text to be appended to `redis.conf`.";
|
||||
};
|
||||
};
|
||||
|
||||
outputs.settings = lib.mkOption {
|
||||
type = types.deferredModule;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = {
|
||||
config = {
|
||||
outputs = {
|
||||
settings = {
|
||||
processes = {
|
||||
"${name}" =
|
||||
let
|
||||
@ -82,7 +81,6 @@ in
|
||||
success_threshold = 1;
|
||||
failure_threshold = 5;
|
||||
};
|
||||
namespace = name;
|
||||
|
||||
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
|
||||
availability.restart = "on_failure";
|
||||
|
@ -46,12 +46,11 @@ in
|
||||
Searxng settings
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
outputs.settings = lib.mkOption {
|
||||
type = types.deferredModule;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = {
|
||||
config = {
|
||||
outputs = {
|
||||
settings = {
|
||||
processes = {
|
||||
"${name}" = {
|
||||
environment = {
|
||||
@ -65,7 +64,6 @@ in
|
||||
)}";
|
||||
};
|
||||
command = lib.getExe config.package;
|
||||
namespace = name;
|
||||
availability.restart = "on_failure";
|
||||
readiness_probe = {
|
||||
exec.command = "${lib.getExe pkgs.curl} -f -k http://${config.host}:${toString config.port}";
|
||||
|
@ -51,12 +51,11 @@ in
|
||||
Additional flags to pass to tempo.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
outputs.settings = lib.mkOption {
|
||||
type = types.deferredModule;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = {
|
||||
config = {
|
||||
outputs = {
|
||||
settings = {
|
||||
processes."${name}" =
|
||||
let
|
||||
tempoConfig = lib.recursiveUpdate
|
||||
@ -126,7 +125,6 @@ in
|
||||
success_threshold = 1;
|
||||
failure_threshold = 5;
|
||||
};
|
||||
namespace = name;
|
||||
availability.restart = "on_failure";
|
||||
};
|
||||
};
|
||||
|
@ -54,12 +54,11 @@ in
|
||||
'';
|
||||
apply = lib.mapAttrs (_: value: toStr (asAtom value));
|
||||
};
|
||||
};
|
||||
|
||||
outputs.settings = lib.mkOption {
|
||||
type = types.deferredModule;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = {
|
||||
config = {
|
||||
outputs = {
|
||||
settings = {
|
||||
processes = {
|
||||
"${name}" =
|
||||
let
|
||||
@ -87,7 +86,6 @@ in
|
||||
success_threshold = 1;
|
||||
failure_threshold = 5;
|
||||
};
|
||||
namespace = name;
|
||||
|
||||
# https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy
|
||||
availability.restart = "on_failure";
|
||||
|
@ -97,11 +97,11 @@ with lib;
|
||||
example = literalExpression "pkgs.jre";
|
||||
type = types.package;
|
||||
};
|
||||
outputs.settings = lib.mkOption {
|
||||
type = types.deferredModule;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = {
|
||||
};
|
||||
|
||||
config = {
|
||||
outputs = {
|
||||
settings = {
|
||||
processes = {
|
||||
"${name}" =
|
||||
let
|
||||
@ -148,7 +148,6 @@ with lib;
|
||||
success_threshold = 1;
|
||||
failure_threshold = 5;
|
||||
};
|
||||
namespace = name;
|
||||
|
||||
availability.restart = "on_failure";
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user