From 82b20a84bc4799a8b2992423f4448340c525496c Mon Sep 17 00:00:00 2001 From: Dan Root Date: Thu, 28 Aug 2025 23:17:06 -0700 Subject: [PATCH] Add all known outstanding yaml config options as of process-compose v1.7.3 - per-process `description` that displays in the UI - global and per-process `log_configuration`, including `rotation` - global and per-process `vars` for supporting Go template expansion on configs - `env_cmds` allows running host commands to populate env variables - `ordered_shutdown` controls the order of process shutdown - `is_strict` does additional checking on configuration files at startup - `disable_env_expansion` to not propagate .env variables to processes - `http_get.{headers,status_code}` and `working_dir` for probe commands - `replicas` to run multiple copies of processes - `entrypoint` alternate to `command` - `is_elevated` for sudo/runas priviledged processes - `extends,is_disabled,is_dotenv_disabled` for multi-file fragments and overrides. - `launch_timeout_seconds` for daemon processes --- nix/process-compose/settings/default.nix | 63 +++++++++- nix/process-compose/settings/log-config.nix | 122 ++++++++++++++++++++ nix/process-compose/settings/probe.nix | 23 ++++ nix/process-compose/settings/process.nix | 100 +++++++++++++++- nix/process-compose/settings/vars.nix | 25 ++++ 5 files changed, 331 insertions(+), 2 deletions(-) create mode 100644 nix/process-compose/settings/log-config.nix create mode 100644 nix/process-compose/settings/vars.nix diff --git a/nix/process-compose/settings/default.nix b/nix/process-compose/settings/default.nix index c00c7d9..a8bd016 100644 --- a/nix/process-compose/settings/default.nix +++ b/nix/process-compose/settings/default.nix @@ -51,7 +51,16 @@ in File to write the logs to. ''; }; - + log_configuration = mkOption { + type = types.nullOr (types.submoduleWith { + specialArgs = { inherit lib; }; + modules = [ ./log-config.nix ]; + }); + default = null; + description = '' + The default settings for global logging. + ''; + }; shell = { shell_argument = mkOption { type = types.str; @@ -82,6 +91,58 @@ in Version of the process-compose configuration. ''; }; + + vars = import ./vars.nix { inherit lib; } { }; + + disable_env_expansion = mkOption { + type = types.nullOr types.bool; + default = null; + example = false; + description = '' + Globally disables automatic \$ variable expansion. + ''; + }; + + ordered_shutdown = mkOption { + type = types.nullOr types.bool; + default = null; + example = true; + description = '' + Causes processes to shut down in reverse dependency order. + ''; + }; + + env_cmds = mkOption { + type = types.nullOr (types.attrsOf types.str); + default = null; + example = { + UPTIME = "uptime -p"; + OS_NAME = "awk -F = '/PRETTY/ {print $2}' /etc/os-release"; + }; + description = '' + Dynamically populate environment variables by executing commands before starting processes. + ''; + }; + + is_strict = mkOption { + type = types.nullOr types.bool; + default = null; + example = true; + description = '' + Enables additional checks on YAML configuration correctness. + ''; + }; + + extends = mkOption { + type = types.nullOr types.path; + default = null; + example = "process-compose.base.yaml"; + description = '' + Make the current configuration inherit all values in the given file. + + See https://f1bonacc1.github.io/process-compose/merge#configuration-inheritance-with-extends + ''; + }; }; }]; }; diff --git a/nix/process-compose/settings/log-config.nix b/nix/process-compose/settings/log-config.nix new file mode 100644 index 0000000..b88a311 --- /dev/null +++ b/nix/process-compose/settings/log-config.nix @@ -0,0 +1,122 @@ +{ name, lib, ... }: + +let + inherit (lib) types mkOption; + inherit (types) nullOr listOf str enum bool; +in +{ + options = { + rotation = mkOption { + type = types.submodule { + options = { + max_size_mb = mkOption { + type = types.nullOr types.ints.unsigned; + default = null; + example = 1; + description = '' + Maximum size in MB of the logfile before it's rolled. + ''; + }; + max_backups = mkOption { + type = types.nullOr types.ints.unsigned; + default = null; + example = 3; + description = '' + Maximum number of rolled logfiles to keep. + ''; + }; + max_age_days = mkOption { + type = types.nullOr types.ints.unsigned; + default = null; + example = 7; + description = '' + Maximum age in days to keep a rolled logfile. + ''; + }; + compress = mkOption { + type = types.nullOr types.bool; + default = null; + example = true; + description = '' + If enabled, compress rolled logfiles with gzip. + ''; + }; + }; + }; + default = { }; + description = '' + Settings related to process log rotation. + ''; + }; + + fields_order = mkOption { + type = nullOr (listOf (enum [ + "time" + "level" + "message" + # technically arbitrary, but these are defined in config. + ]) + ); + default = null; + example = [ + "time" + "level" + "message" + ]; + description = '' + Order of logging fields. The default is time, level, message + ''; + }; + disable_json = mkOption { + type = nullOr bool; + default = null; + example = false; + description = '' + If enabled, output as plain text rather than json. + ''; + }; + timestamp_format = mkOption { + type = nullOr str; + default = null; + example = "2006-01-02T15:04:05.000Z"; + description = '' + Timestamp format, per Go's time.Parse function. + Requires `add_timestamp` be enabled to be effective. + + See https://pkg.go.dev/time#pkg-constants for examples. + ''; + }; + no_color = mkOption { + type = nullOr bool; + default = null; + example = false; + description = '' + Enabling `no_color` prevents the use of ANSI colors in the logger. + ''; + }; + no_metadata = mkOption { + type = nullOr bool; + default = null; + example = true; + description = '' + If enabled, do not add process name and replica number to logs. + ''; + }; + add_timestamp = mkOption { + type = nullOr bool; + default = null; + example = true; + description = '' + If enabled, prepends a timestamp to log entries. + ''; + }; + flush_each_line = mkOption { + type = nullOr bool; + default = null; + example = true; + description = '' + If enabled, disables output buffering and flushes each line to the logfile immediately. + ''; + }; + }; +} diff --git a/nix/process-compose/settings/probe.nix b/nix/process-compose/settings/probe.nix index c4d6b17..9fb7450 100644 --- a/nix/process-compose/settings/probe.nix +++ b/nix/process-compose/settings/probe.nix @@ -49,6 +49,22 @@ in Which port to probe the process on. ''; }; + headers = mkOption { + type = types.nullOr (types.attrsOf types.str); + default = null; + example = { "x-foo" = "bar"; }; + description = '' + Additional headers to set on an HTTP probe + ''; + }; + status_code = mkOption { + type = types.nullOr types.int; + default = null; + example = 200; + description = '' + Expected status code. + ''; + }; }; }); default = null; @@ -62,6 +78,13 @@ in The command to execute in order to check the health of the process. ''; }; + options.working_dir = mkOption { + type = types.str; + example = "./directory"; + description = '' + Directory in which to execute the exec probe command. + ''; + }; }); default = null; description = '' diff --git a/nix/process-compose/settings/process.nix b/nix/process-compose/settings/process.nix index f65bcb1..5442f72 100644 --- a/nix/process-compose/settings/process.nix +++ b/nix/process-compose/settings/process.nix @@ -119,6 +119,14 @@ in Wait for `timeout_seconds` for its completion (if not defined wait for 10 seconds). Upon timeout, `SIGKILL` is sent to the process. ''; }; + parent_only = mkOption { + type = types.nullOr types.bool; + default = null; + example = false; + description = '' + If `shutdown.parent_only` is enabled, the termination signal is only sent to the parent process, not the whole group. + ''; + }; }; working_dir = mkOption { @@ -172,6 +180,18 @@ in Log location of the `process-compose` process. ''; }; + + log_configuration = mkOption { + type = types.nullOr (types.submoduleWith { + specialArgs = { inherit lib; }; + modules = [ ./log-config.nix ]; + }); + default = { }; + description = '' + The settings for process-specific logging. + ''; + }; + disable_ansi_colors = mkOption { type = types.nullOr types.bool; default = null; @@ -217,10 +237,88 @@ in example = true; description = '' Whether the process is disabled. Useful when a process is required to be started only in a given scenario, like while running in CI. - + Even if disabled, the process is still listed in the TUI and the REST client, and can be started manually when needed. ''; }; + vars = import ./vars.nix { inherit lib; } { }; + + replicas = mkOption { + type = types.nullOr types.int; + default = null; + example = 2; + description = '' + Run multiple replicas of a given process. + + Will set the PC_REPLICA_NUM var for expansion such that configs can run on unique ports or similar. + ''; + }; + + description = mkOption { + type = types.nullOr types.str; + default = null; + example = "process does a thing"; + description = '' + Set a description for the process in the UI. + ''; + }; + + entrypoint = mkOption { + type = types.nullOr (types.listOf types.str); + default = null; + example = [ + "ls" + "-l" + "/some/dir" + ]; + description = '' + Specifies the process command as a list of arguments. + Overridden by the command option if it is present. + ''; + }; + + is_elevated = mkOption { + type = types.nullOr types.bool; + default = null; + example = true; + description = '' + Run the command with elevated permissions, + using sudo or runas. + ''; + }; + + is_disabled = mkOption { + type = types.nullOr types.bool; + default = null; + example = false; + description = '' + Allows turning off the disabled flag when dealing with merged configs via `extend` or multiple config file command arguments. + + is_disabled has priority over disabled, so in general: + - use disabled in base or primary configurations + - use is_disabled in override configurations. + ''; + }; + + is_dotenv_disabled = mkOption { + type = types.nullOr types.bool; + default = null; + example = true; + description = '' + If set to true, prevents process-compose from loading any .env files in the working directory. + + Does not prevent other sources of env variables, such as the env section of the configuration. + ''; + }; + + launch_timeout_seconds = mkOption { + type = types.nullOr types.int; + default = null; + example = 2; + description = '' + If a parent process with is_daemon takes longer than this to fork in to the background, process-compose will stop waiting for logs and start waiting for process termination. + ''; + }; }; } diff --git a/nix/process-compose/settings/vars.nix b/nix/process-compose/settings/vars.nix new file mode 100644 index 0000000..b82e58e --- /dev/null +++ b/nix/process-compose/settings/vars.nix @@ -0,0 +1,25 @@ +{ lib, ... }: +let + inherit (lib) types; + inherit (types) nullOr attrsOf anything; +in +args: +lib.mkOption ( + args + // { + # maybe YAML/JSON limited or smarter coerce to string? + type = nullOr (attrsOf anything); + description = '' + Variables used by process-compose to expand Go Template configs on various values. + + Includes processes.process.command, working_dir, log_location, etc. + See https://f1bonacc1.github.io/process-compose/configuration#variables + ''; + default = null; + example = { + THIS = "THAT"; + A_NUMBER = 8888; + OK = "SUCCESS"; + }; + } +)