Skip to content
Draft
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
48 changes: 48 additions & 0 deletions doc/custom-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<name>` option.
> Examples:
> - Bad:
> ```nix
> # Definition
> { config, ... }:
> {
> options = {
> ...
> extraEnvironment = lib.mkOption {
> type = lib.types.attrs;
> default = { };
> };
> };
> config = {
> outputs.settings = {
> processes.<name> = {
> environment = <defaults> // config.extraEnvironment;
> };
> };
> };
>
> }
>
> # Usage
> {
> services.<name>.<name> = {
> extraEnvironment = ...
> };
> }
> ```
> - Good:
> ```nix
>
> # No change in definition
>
> # Usage
> {
> services.<name>.<name> = {
> processSettings.<name> = {
> environment = ...;
> };
> };
> }
> ```


## See also

- [Postgres with replica](https://github.com/nammayatri/nammayatri/blob/main/Backend/nix/services/postgres-with-replica.nix)
Expand Down
8 changes: 5 additions & 3 deletions example/llm/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
25 changes: 16 additions & 9 deletions nix/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
default = "./data/${name}";
description = "The directory where all data for `${service}.<name>` 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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lazyAttrsOf because a service can define multiple processes (postgres, postgres-init for example)

description = "Settings for a process-compose process defined in this service";
default = { };
apply = v: {
processes = v;
};
};
outputs = {
defaultProcessSettings = lib.mkOption {
Expand All @@ -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 {
Expand All @@ -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
];
}
);
};
};
Expand Down Expand Up @@ -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
];
};
};
Expand Down