services-flake/example/flake.nix
Shivaraj B H bf3a582502
[Postgres]: Fix test process not starting (#78)
* needn't copy depends_on option, demonstrated in example/flake.nix

* postgres: test process must depend on both pg1 and pg2
2024-01-18 11:28:15 +05:30

76 lines
2.5 KiB
Nix

{
description = "A demo of sqlite-web and multiple postgres services";
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";
services-flake.url = "github:juspay/services-flake";
northwind.url = "github:pthom/northwind_psql";
northwind.flake = false;
};
outputs = inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = import inputs.systems;
imports = [
inputs.process-compose-flake.flakeModule
];
perSystem = { self', pkgs, lib, ... }: {
# This adds a `self.packages.default`
process-compose."default" = { config, ... }:
let
dbName = "sample";
in
{
imports = [
inputs.services-flake.processComposeModules.default
];
services.postgres."pg1" = {
enable = true;
listen_addresses = "127.0.0.1";
initialDatabases = [
{
name = dbName;
schemas = [ "${inputs.northwind}/northwind.sql" ];
}
];
};
services.postgres."pg2" = {
enable = true;
listen_addresses = "127.0.0.1";
port = 5433;
};
# Start `pg2-init` process after `pg1-init`
settings.processes."pg2-init".depends_on."pg1-init".condition = "process_completed_successfully";
settings.processes.pgweb =
let
pgcfg = config.services.postgres.pg1;
in
{
environment.PGWEB_DATABASE_URL = "postgres://$USER@${pgcfg.listen_addresses}:${builtins.toString pgcfg.port}/${dbName}";
command = pkgs.pgweb;
depends_on."pg1".condition = "process_healthy";
};
settings.processes.test = {
command = pkgs.writeShellApplication {
name = "pg1-test";
runtimeInputs = [ config.services.postgres.pg1.package ];
text = ''
echo 'SELECT version();' | psql -h 127.0.0.1 ${dbName}
'';
};
depends_on."pg1".condition = "process_healthy";
};
};
devShells.default = pkgs.mkShell {
nativeBuildInputs = [ pkgs.just ];
};
};
};
}