From 930aed5595b6255aac4cfc466b969e38c91df7a1 Mon Sep 17 00:00:00 2001 From: shivaraj-bh Date: Sun, 21 Jan 2024 01:25:25 +0530 Subject: [PATCH] add getting started page; enable higlightjs --- doc/services-flake.yaml | 2 ++ doc/services-flake/services.md | 20 ++++++++++++ doc/services-flake/start.md | 60 ++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 doc/services-flake/services.md create mode 100644 doc/services-flake/start.md diff --git a/doc/services-flake.yaml b/doc/services-flake.yaml index 7ec8672f..9608cb73 100644 --- a/doc/services-flake.yaml +++ b/doc/services-flake.yaml @@ -3,6 +3,8 @@ page: siteTitle: services-flake + headHtml: | + template: # You can add your own variables here, like editBaseUrl. diff --git a/doc/services-flake/services.md b/doc/services-flake/services.md new file mode 100644 index 00000000..e232db02 --- /dev/null +++ b/doc/services-flake/services.md @@ -0,0 +1,20 @@ +--- +short-title: Services +--- + +# Supported services + +>[!warning] +> This list denotes the progress of documentation, not implementation. See full list of implemented services at [gh]. + +- [ ] Apache Kafka +- [ ] Elasticsearch +- [ ] MySQL +- [ ] Nginx +- [ ] PostgreSQL +- [ ] Redis +- [ ] Redis Cluster +- [ ] Zookeeper +- [ ] ... + +[gh]: https://github.com/juspay/services-flake diff --git a/doc/services-flake/start.md b/doc/services-flake/start.md new file mode 100644 index 00000000..6f816a34 --- /dev/null +++ b/doc/services-flake/start.md @@ -0,0 +1,60 @@ +--- +order: -10 +--- + +# Getting started + + +## New project + +Use the [template flake](https://github.com/juspay/services-flake/blob/main/example/flake.nix) provided by `services-flake`: +```sh +mkdir example && cd ./example +nix flake init -t github:juspay/services-flake +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 +{ + 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 = [ + inputs.process-compose-flake.flakeModule + ]; + perSystem = { ... }: { + process-compose."default" = { + imports = [ + inputs.services-flake.processComposeModules.default + ]; + }; + } + }; +} +``` +As an example, let's add the [[redis]] service to your flake: +```nix +# Inside `perSystem.process-compose.default` +{ + services.redis."r1".enable = true; +} +``` + +Time to run the service: +```sh +nix run +``` + +## 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]. + +[^how-default]: `default` is the name of the process group that is derived from `process-compose.` 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.