Skip to content

Commit

Permalink
docs(start): Improve a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
srid authored Jun 4, 2024
1 parent 24a7b57 commit f7e6af5
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions doc/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ nix run
## Existing project

services-flake uses [process-compose-flake](https://community.flake.parts/process-compose-flake) to manage the services. Let's first import the `flake-parts` modules provided by `process-compose-flake` and `services-flake` in your flake:

```nix
{
# 1. Add the inputs
inputs.process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
inputs.services-flake.url = "github:juspay/services-flake";
...
outputs = inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
# 2. Import the flake-module
inputs.process-compose-flake.flakeModule
];
perSystem = { ... }: {
process-compose."default" = {
# 3. Create the process-compose configuration, importing services-flake
process-compose."myservices" = {
imports = [
inputs.services-flake.processComposeModules.default
];
Expand All @@ -37,25 +41,28 @@ services-flake uses [process-compose-flake](https://community.flake.parts/proces
};
}
```

As an example, let's add the `redis` service to your flake:

```nix
# Inside `perSystem.process-compose.default`
# Inside `perSystem.process-compose."myservices"`
{
services.redis."r1".enable = true;
}
```

Time to run the service:

```sh
nix run
nix run .#myservices
```

## Under the hood

- The `services-flake` module configures [process settings](https://community.flake.parts/process-compose-flake#usage) for a service. In simple terms, it handles stuff like health checks, restart policies, setup scripts, etc. by using the easy to configure APIs provided by `process-compose-flake`.
- The `process-compose-flake` module uses these settings to generate `packages.${system}.default`[^how-default] (`nix run` above, runs this package by default), which runs [process-compose](https://github.com/F1bonacc1/process-compose) with the generated YAML configuration[^sample-config].
- The `process-compose-flake` module uses these settings to generate `packages.${system}.myservices`[^how-default] (`nix run .#myservices` above, [runs](https://nixos.asia/en/nix-first#run) this package by default), which runs [process-compose](https://github.com/F1bonacc1/process-compose) with the generated YAML configuration[^sample-config].

[^how-default]: `default` is the name of the process group that is derived from `process-compose.<name>` in `perSystem.process-compose`.
[^how-default]: `myservices` is the name of the process group that is derived from `process-compose.<name>` in `perSystem.process-compose`.

[^sample-config]: See the example configuration from the [getting started](https://f1bonacc1.github.io/process-compose/intro/) section of the process-compose docs.

Expand Down

0 comments on commit f7e6af5

Please sign in to comment.