From e852b77d604f95d20b5c841a16e70fa52ff21563 Mon Sep 17 00:00:00 2001 From: shivaraj-bh Date: Fri, 31 Oct 2025 16:07:57 +0530 Subject: [PATCH 1/7] feat: Provide granular control to modify the process from the service options --- nix/lib.nix | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/nix/lib.nix b/nix/lib.nix index a9078f48..f54c9839 100644 --- a/nix/lib.nix +++ b/nix/lib.nix @@ -21,12 +21,10 @@ default = "./data/${name}"; description = "The directory where all data for `${service}.` is stored"; }; - namespace = lib.mkOption { - description = '' - Namespace for the ${service} service - ''; - default = "${service}.${name}"; - type = lib.types.str; + settings.processes = lib.mkOption { + type = lib.types.lazyAttrsOf lib.types.deferredModule; + description = "Settings for a process-compose process defined in this service"; + default = { }; }; outputs = { defaultProcessSettings = lib.mkOption { @@ -37,7 +35,7 @@ Default settings for all processes under the ${service} service ''; default = { - namespace = lib.mkDefault config.namespace; + namespace = lib.mkDefault "${service}.${name}"; }; }; settings = lib.mkOption { @@ -47,8 +45,14 @@ 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 ]; } + processes = lib.flip lib.mapAttrs v.processes (pName: cfg: + { + imports = [ + config.processSettings + config.outputs.defaultProcessSettings + cfg + ] ++ lib.optional (lib.hasAttr pName config.settings.processes) config.settings.processes.${pName}; + } ); }; }; From 62ce133a1778b3795564df6f0d577bd9b97dabf9 Mon Sep 17 00:00:00 2001 From: shivaraj-bh Date: Fri, 31 Oct 2025 16:14:47 +0530 Subject: [PATCH 2/7] chore: processSettings settings.processes will interfere with existing settings option in a service. See mysql's options for ex. --- nix/lib.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nix/lib.nix b/nix/lib.nix index f54c9839..996e3205 100644 --- a/nix/lib.nix +++ b/nix/lib.nix @@ -21,7 +21,7 @@ default = "./data/${name}"; description = "The directory where all data for `${service}.` is stored"; }; - settings.processes = lib.mkOption { + processSettings = lib.mkOption { type = lib.types.lazyAttrsOf lib.types.deferredModule; description = "Settings for a process-compose process defined in this service"; default = { }; @@ -51,7 +51,7 @@ config.processSettings config.outputs.defaultProcessSettings cfg - ] ++ lib.optional (lib.hasAttr pName config.settings.processes) config.settings.processes.${pName}; + ] ++ lib.optional (lib.hasAttr pName config.processSettings) config.processSettings.${pName}; } ); }; From e8b176db6c990e81b7cc5d96f6b32d6e4ee4fe76 Mon Sep 17 00:00:00 2001 From: shivaraj-bh Date: Fri, 31 Oct 2025 16:27:35 +0530 Subject: [PATCH 3/7] chore: ah --- nix/lib.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/nix/lib.nix b/nix/lib.nix index 996e3205..93ee0f77 100644 --- a/nix/lib.nix +++ b/nix/lib.nix @@ -48,7 +48,6 @@ processes = lib.flip lib.mapAttrs v.processes (pName: cfg: { imports = [ - config.processSettings config.outputs.defaultProcessSettings cfg ] ++ lib.optional (lib.hasAttr pName config.processSettings) config.processSettings.${pName}; From ac14bb382c3831b7d1cbbbf380b9d2a0d9ee6c89 Mon Sep 17 00:00:00 2001 From: shivaraj-bh Date: Mon, 3 Nov 2025 03:40:35 +0530 Subject: [PATCH 4/7] chore: discard lib.hasAttr --- nix/lib.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nix/lib.nix b/nix/lib.nix index 93ee0f77..ede5be11 100644 --- a/nix/lib.nix +++ b/nix/lib.nix @@ -50,7 +50,8 @@ imports = [ config.outputs.defaultProcessSettings cfg - ] ++ lib.optional (lib.hasAttr pName config.processSettings) config.processSettings.${pName}; + config.processSettings.${pName} + ]; } ); }; From 0f22ac7c8fba01cec58357e6297860aa005a4089 Mon Sep 17 00:00:00 2001 From: shivaraj-bh Date: Mon, 3 Nov 2025 03:41:09 +0530 Subject: [PATCH 5/7] docs: add --- doc/custom-service.md | 49 +++++++++++++++++++++++++++++++++++++++++++ example/llm/flake.nix | 8 ++++--- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/doc/custom-service.md b/doc/custom-service.md index 3f010f7b..04fa6b82 100644 --- a/doc/custom-service.md +++ b/doc/custom-service.md @@ -161,6 +161,55 @@ Now that we have defined the multi-instance service, we can import it in our fla And finally, `nix run`: ![[multi-instance-hello.png]] +> [!TIP] +> Do not introduce new options to configure underlying process-compose settings of a process, use the default `processSettings.` option. +> +> ```nix +> # Bad +> +> # Definition +> { config, ... }: +> { +> options = { +> ... +> extraEnvironment = lib.mkOption { +> type = lib.types.attrs; +> default = { }; +> }; +> }; +> config = { +> outputs.settings = { +> processes. = { +> environment = // config.extraEnvironment; +> }; +> }; +> }; +> +> } +> +> # Usage +> { +> services.. = { +> extraEnvironment = ... +> }; +> } +> ``` +> ```nix +> # Good +> +> # No change in definition +> +> # Usage +> { +> services.. = { +> processSettings. = { +> environment = ...; +> }; +> }; +> } +> ``` + + ## See also - [Postgres with replica](https://github.com/nammayatri/nammayatri/blob/main/Backend/nix/services/postgres-with-replica.nix) diff --git a/example/llm/flake.nix b/example/llm/flake.nix index 19e40c92..531b4f93 100644 --- a/example/llm/flake.nix +++ b/example/llm/flake.nix @@ -68,12 +68,14 @@ # RAG_RERANKING_MODEL_AUTO_UPDATE = "True"; # DEVICE_TYPE = "cpu"; }; + processSettings."open-webui1" = { + # Modify the process-compose setting + # Start the Open WebUI service after the Ollama service has finished initializing and loading the models + depends_on.ollama1-models.condition = "process_completed_successfully"; + }; }; }; - # Start the Open WebUI service after the Ollama service has finished initializing and loading the models - settings.processes.open-webui1.depends_on.ollama1-models.condition = "process_completed_successfully"; - # Open the browser after the Open WebUI service has started settings.processes.open-browser = { command = From 1c181987a66899ee2c5b0ecc09e2e6497366121d Mon Sep 17 00:00:00 2001 From: shivaraj-bh Date: Mon, 3 Nov 2025 04:12:15 +0530 Subject: [PATCH 6/7] docs: fix render --- doc/custom-service.md | 79 +++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/doc/custom-service.md b/doc/custom-service.md index 04fa6b82..cbab61fe 100644 --- a/doc/custom-service.md +++ b/doc/custom-service.md @@ -163,51 +163,50 @@ And finally, `nix run`: > [!TIP] > Do not introduce new options to configure underlying process-compose settings of a process, use the default `processSettings.` option. -> -> ```nix -> # Bad -> -> # Definition -> { config, ... }: -> { -> options = { -> ... -> extraEnvironment = lib.mkOption { -> type = lib.types.attrs; -> default = { }; -> }; -> }; -> config = { -> outputs.settings = { -> processes. = { -> environment = // config.extraEnvironment; +> Examples: +> - Bad: +> ```nix +> # Definition +> { config, ... }: +> { +> options = { +> ... +> extraEnvironment = lib.mkOption { +> type = lib.types.attrs; +> default = { }; +> }; +> }; +> config = { +> outputs.settings = { +> processes. = { +> environment = // config.extraEnvironment; +> }; +> }; > }; -> }; -> }; > -> } +> } > -> # Usage -> { -> services.. = { -> extraEnvironment = ... -> }; -> } -> ``` -> ```nix -> # Good +> # Usage +> { +> services.. = { +> extraEnvironment = ... +> }; +> } +> ``` +> - Good: +> ```nix > -> # No change in definition +> # No change in definition > -> # Usage -> { -> services.. = { -> processSettings. = { -> environment = ...; -> }; -> }; -> } -> ``` +> # Usage +> { +> services.. = { +> processSettings. = { +> environment = ...; +> }; +> }; +> } +> ``` ## See also From 722ca7baa0ff33e49812c93efdfed8167b875870 Mon Sep 17 00:00:00 2001 From: shivaraj-bh Date: Tue, 4 Nov 2025 16:13:24 +0530 Subject: [PATCH 7/7] fix: don't enforce defining `processSettings.` for all processes of a service --- nix/lib.nix | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nix/lib.nix b/nix/lib.nix index ede5be11..481d4b28 100644 --- a/nix/lib.nix +++ b/nix/lib.nix @@ -25,6 +25,9 @@ type = lib.types.lazyAttrsOf lib.types.deferredModule; description = "Settings for a process-compose process defined in this service"; default = { }; + apply = v: { + processes = v; + }; }; outputs = { defaultProcessSettings = lib.mkOption { @@ -45,12 +48,11 @@ process-compose settings for the processes under the ${service} service ''; apply = v: v // { - processes = lib.flip lib.mapAttrs v.processes (pName: cfg: + processes = lib.flip lib.mapAttrs v.processes (_: cfg: { imports = [ config.outputs.defaultProcessSettings cfg - config.processSettings.${pName} ]; } ); @@ -81,7 +83,8 @@ imports = lib.pipe config.services.${service} [ (lib.filterAttrs (_: cfg: cfg.enable)) - (lib.mapAttrsToList (_: cfg: cfg.outputs.settings)) + (lib.mapAttrsToList (_: cfg: [ cfg.outputs.settings cfg.processSettings ])) + lib.concatLists ]; }; };