Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- #39: Allow `test` process to act as a test, which then gets run as part of flake checks.
- #55: Add `lib` flake output - library of useful functions
- #80: Add `evalModules`, to use process-compose-flake without flake-parts
- #102: Add `defaults.processSettings` option to set default settings for all processes
- New options
- #52: Add `is_foreground` option
- ~~#54: Add `apiServer` option to control REST API server~~
Expand Down
34 changes: 34 additions & 0 deletions doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,40 @@ process-compose.watch-server = {
};
```

### Default settings for all processes

You can define default settings that apply to all processes using `defaults.processSettings`. This is useful when you want to set common configuration like namespace, restart behavior, or other settings across all processes.

```nix
process-compose.watch-server = {
defaults.processSettings = { name, ... }: {
# Set default namespace for all processes
namespace = lib.mkDefault "watch-server";
# Set default restart behavior
availability.restart = lib.mkDefault "on_failure";
availability.max_restarts = lib.mkDefault 3;
# Use the process name in log locations
log_location = ".logs/${name}.log";
};

settings.processes = {
backend-server.command = "...";
frontend-server.command = "...";
# This process overrides the default namespace
proxy-server = {
command = "...";
namespace = "proxy"; # Overrides the default
};
};
};
```

**Important:** Use `lib.mkDefault` when setting defaults to ensure individual process settings can override them.

You can access the process `name` parameter to create dynamic defaults (e.g., per-process log files).

You can disable defaults entirely by setting `defaults.enable = false`.

## Module API

Our submodule mirrors the [process-compose YAML schema](https://github.com/F1bonacc1/process-compose/blob/main/process-compose.yaml). A few things to remember:
Expand Down
5 changes: 5 additions & 0 deletions example/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
dataFile = "data.sqlite";
in
{
# Default settings for all processes
defaults.processSettings = {
namespace = lib.mkDefault "sqlite-demo";
};

cli = {
# environment.PC_DISABLE_TUI = true;
# Global options for `process-compose`
Expand Down
1 change: 1 addition & 0 deletions nix/process-compose/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ in
{
imports = [
./cli.nix
./defaults.nix
./settings
./test.nix
];
Expand Down
43 changes: 43 additions & 0 deletions nix/process-compose/defaults.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# A module representing the default values for all processes in process-compose-flake.
{ name, lib, config, ... }:
let
inherit (lib)
mkOption
types;
in
{
options.defaults = {
enable = mkOption {
type = types.bool;
description = ''
Whether to enable default settings for processes in this configuration.
'';
default = true;
};

processSettings = mkOption {
type = types.deferredModule;
description = ''
Default settings that will be applied to all processes in this configuration.

Individual process settings can override these defaults. When setting defaults,
use `lib.mkDefault` to ensure individual process settings take precedence.

Example:
```nix
defaults.processSettings = {
availability.restart = lib.mkDefault "on_failure";
availability.max_restarts = lib.mkDefault 3;
namespace = lib.mkDefault "myapp";
};
```
'';
apply = settings:
if config.defaults.enable then
settings
else
{ };
default = { };
};
};
}
7 changes: 6 additions & 1 deletion nix/process-compose/settings/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ in
modules = [{
options = {
processes = mkOption {
type = types.attrsOf (types.submoduleWith { modules = [ ./process.nix ]; });
type = types.attrsOf (types.submoduleWith {
modules = [
./process.nix
config.defaults.processSettings
];
});
default = { };
description = ''
A map of process names to their configuration.
Expand Down
2 changes: 1 addition & 1 deletion nix/process-compose/settings/process.nix
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ 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.
'';
};
Expand Down
Loading