Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion nix/process-compose/settings/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
'';
};
};
}];
};
Expand Down
122 changes: 122 additions & 0 deletions nix/process-compose/settings/log-config.nix
Original file line number Diff line number Diff line change
@@ -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.
'';
};
};
}
23 changes: 23 additions & 0 deletions nix/process-compose/settings/probe.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = ''
Expand Down
100 changes: 99 additions & 1 deletion nix/process-compose/settings/process.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
'';
};
};
}
25 changes: 25 additions & 0 deletions nix/process-compose/settings/vars.nix
Original file line number Diff line number Diff line change
@@ -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";
};
}
)