diff --git a/doc/custom-service.md b/doc/custom-service.md index 3f010f7b..cbab61fe 100644 --- a/doc/custom-service.md +++ b/doc/custom-service.md @@ -161,6 +161,54 @@ 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. +> Examples: +> - Bad: +> ```nix +> # Definition +> { config, ... }: +> { +> options = { +> ... +> extraEnvironment = lib.mkOption { +> type = lib.types.attrs; +> default = { }; +> }; +> }; +> config = { +> outputs.settings = { +> processes. = { +> environment = // config.extraEnvironment; +> }; +> }; +> }; +> +> } +> +> # Usage +> { +> services.. = { +> extraEnvironment = ... +> }; +> } +> ``` +> - Good: +> ```nix +> +> # 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 = diff --git a/nix/lib.nix b/nix/lib.nix index a9078f48..481d4b28 100644 --- a/nix/lib.nix +++ b/nix/lib.nix @@ -21,12 +21,13 @@ 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; + processSettings = lib.mkOption { + 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 { @@ -37,7 +38,7 @@ Default settings for all processes under the ${service} service ''; default = { - namespace = lib.mkDefault config.namespace; + namespace = lib.mkDefault "${service}.${name}"; }; }; settings = lib.mkOption { @@ -48,7 +49,12 @@ ''; apply = v: v // { processes = lib.flip lib.mapAttrs v.processes (_: cfg: - { imports = [ config.outputs.defaultProcessSettings cfg ]; } + { + imports = [ + config.outputs.defaultProcessSettings + cfg + ]; + } ); }; }; @@ -77,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 ]; }; };