From 5d055bac46dbd12e49fe9cccf55cf2fef04de80f Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Wed, 19 Nov 2025 16:57:48 -0500 Subject: [PATCH 1/5] impl --- example/flake.nix | 5 +++ nix/process-compose/default.nix | 1 + nix/process-compose/defaults.nix | 43 ++++++++++++++++++++++++ nix/process-compose/settings/default.nix | 7 +++- nix/process-compose/settings/process.nix | 2 +- 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 nix/process-compose/defaults.nix diff --git a/example/flake.nix b/example/flake.nix index 396330d..1c91fb7 100644 --- a/example/flake.nix +++ b/example/flake.nix @@ -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` diff --git a/nix/process-compose/default.nix b/nix/process-compose/default.nix index 8ce07d9..c24d5b3 100644 --- a/nix/process-compose/default.nix +++ b/nix/process-compose/default.nix @@ -6,6 +6,7 @@ in { imports = [ ./cli.nix + ./defaults.nix ./settings ./test.nix ]; diff --git a/nix/process-compose/defaults.nix b/nix/process-compose/defaults.nix new file mode 100644 index 0000000..ad310ca --- /dev/null +++ b/nix/process-compose/defaults.nix @@ -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 = { }; + }; + }; +} diff --git a/nix/process-compose/settings/default.nix b/nix/process-compose/settings/default.nix index c00c7d9..327f4f0 100644 --- a/nix/process-compose/settings/default.nix +++ b/nix/process-compose/settings/default.nix @@ -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. diff --git a/nix/process-compose/settings/process.nix b/nix/process-compose/settings/process.nix index f65bcb1..3e64617 100644 --- a/nix/process-compose/settings/process.nix +++ b/nix/process-compose/settings/process.nix @@ -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. ''; }; From 1097936eb5e60b8d25bed95f06c26d7e841b4dce Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Wed, 19 Nov 2025 17:04:48 -0500 Subject: [PATCH 2/5] doc --- CHANGELOG.md | 1 + doc/index.md | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0fdc82..2436a29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 + - 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~~ diff --git a/doc/index.md b/doc/index.md index 557a24e..b5a9162 100644 --- a/doc/index.md +++ b/doc/index.md @@ -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: From bd909f2f006ea56e986721eee18a2ce138c8cda7 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Wed, 19 Nov 2025 17:09:30 -0500 Subject: [PATCH 3/5] ch num --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2436a29..4c5658f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +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 - - Add `defaults.processSettings` option to set default settings for all processes + - #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~~ From c5e36434c427cf0a496951963c3b52d5d09020e6 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Wed, 19 Nov 2025 17:15:49 -0500 Subject: [PATCH 4/5] fix? --- nix/flake-module.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix/flake-module.nix b/nix/flake-module.nix index 452f1f8..0e45059 100644 --- a/nix/flake-module.nix +++ b/nix/flake-module.nix @@ -7,6 +7,7 @@ let types; in { + _file = ./flake-module.nix; options.perSystem = mkPerSystemOption ({ config, pkgs, lib, ... }: { options.process-compose = mkOption { From a3991c98d39802ff2729b68f9bc902372ddbb889 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Wed, 19 Nov 2025 17:20:36 -0500 Subject: [PATCH 5/5] Revert "fix?" This reverts commit c5e36434c427cf0a496951963c3b52d5d09020e6. --- nix/flake-module.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/nix/flake-module.nix b/nix/flake-module.nix index 0e45059..452f1f8 100644 --- a/nix/flake-module.nix +++ b/nix/flake-module.nix @@ -7,7 +7,6 @@ let types; in { - _file = ./flake-module.nix; options.perSystem = mkPerSystemOption ({ config, pkgs, lib, ... }: { options.process-compose = mkOption {