Add an example, expose it as flake template

This commit is contained in:
Sridhar Ratnakumar 2023-06-08 16:39:53 -04:00
parent aee1b8d126
commit 6fc00fe344
5 changed files with 186 additions and 0 deletions

2
.gitignore vendored
View File

@ -0,0 +1,2 @@
/example/data.sqlite
/example/result

View File

@ -5,6 +5,20 @@ This `flake-parts` module allows you to declare one or more `process-compose` co
This module is practical for local development e.g. if you have a lot of runtime dependencies that depend on each other. Stop executing these programs imperatively over and over again in a specific order, and stop the need to write complicated shell scripts to automate this. `process-compose` gives you a process dashboard for monitoring, inspecting logs for each process, and much more, all of this in a TUI.
## Quick Example
See [`./example/flake.nix`](example/flake.nix) for an example flake. This example shows a demo of [sqlite-web](https://github.com/coleifer/sqlite-web) using the using the sample [chinhook-database](https://github.com/lerocha/chinook-database).
To run this example locally,
```sh
mkdir example && cd example
nix flake init -t github:Platonic-Systems/process-compose-flake
nix run
```
This should open http://127.0.0.1:8080/ in your web browser. If not, navigate to the logs for the `sqlite-web` process and access the URL.
## Usage
Let's say you want to have a `devShell` that makes a command `watch-server` available, that you can use to spin up your projects `backend-server`, `frontend-server`, and `proxy-server`.

113
example/flake.lock Normal file
View File

@ -0,0 +1,113 @@
{
"nodes": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1685662779,
"narHash": "sha256-cKDDciXGpMEjP1n6HlzKinN0H+oLmNpgeCTzYnsA2po=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "71fb97f0d875fd4de4994dfb849f2c75e17eb6c3",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1686089707,
"narHash": "sha256-LTNlJcru2qJ0XhlhG9Acp5KyjB774Pza3tRH0pKIb3o=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "af21c31b2a1ec5d361ed8050edd0303c31306397",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"dir": "lib",
"lastModified": 1685564631,
"narHash": "sha256-8ywr3AkblY4++3lIVxmrWZFzac7+f32ZEhH/A8pNscI=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "4f53efe34b3a8877ac923b9350c874e3dcd5dc0a",
"type": "github"
},
"original": {
"dir": "lib",
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"process-compose-flake": {
"locked": {
"lastModified": 1680797953,
"narHash": "sha256-lFYbfId1IX6jh/wUf+gt3LyvE9HblS4hcBQcougSzX0=",
"owner": "Platonic-Systems",
"repo": "process-compose-flake",
"rev": "aee1b8d126a5efe5945513eb2fb343f3d68dca4b",
"type": "github"
},
"original": {
"owner": "Platonic-Systems",
"repo": "process-compose-flake",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"process-compose-flake": "process-compose-flake",
"chinookDb": "chinookDb",
"systems": "systems"
}
},
"chinookDb": {
"flake": false,
"locked": {
"lastModified": 1645319735,
"narHash": "sha256-mrRf6ih55mHpaxiw+owvxLPVzRIbxxaj2rWEmLI5pZQ=",
"owner": "lerocha",
"repo": "chinook-database",
"rev": "e7e6d5f008e35d3f89d8b8a4f8d38e3bfa7e34bd",
"type": "github"
},
"original": {
"owner": "lerocha",
"repo": "chinook-database",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

52
example/flake.nix Normal file
View File

@ -0,0 +1,52 @@
{
description = "A demo of sqlite-web";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
systems.url = "github:nix-systems/default";
process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
chinookDb.url = "github:lerocha/chinook-database";
chinookDb.flake = false;
};
outputs = inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = import inputs.systems;
imports = [
inputs.process-compose-flake.flakeModule
];
perSystem = { pkgs, lib, ... }: {
process-compose = {
# This adds a `self.packages.default`
configs."default" = {
processes = {
# Print a pony every 2 seconds, because why not.
ponysay.command = ''
while true; do
${lib.getExe pkgs.ponysay} "Enjoy our sqlite-web demo!"
sleep 2
done
'';
# Create .sqlite database from chinook database.
sqlite-init.command = ''
echo "`date`: Importing Chinook database..."
${lib.getExe pkgs.sqlite} data.sqlite < ${inputs.chinookDb}/ChinookDatabase/DataSources/Chinook_Sqlite.sql
echo "`date`: Done."
'';
# Run sqlite-web on the local chinook database.
sqlite-web = {
command = ''
${pkgs.sqlite-web}/bin/sqlite_web data.sqlite
'';
# The 'depends_on' will have this process wait until the above one is completed.
depends_on."sqlite-init".condition = "process_completed_successfully";
};
};
};
};
};
};
}

View File

@ -1,5 +1,10 @@
{
outputs = { self, ... }: {
flakeModule = ./flake-module.nix;
templates.default = {
description = "Example flake using process-compose-flake";
path = builtins.path { path = ./example; filter = path: _: baseNameOf path == "flake.nix"; };
};
};
}