services-flake/example/flake.nix

69 lines
2.3 KiB
Nix
Raw Normal View History

{
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";
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, ... }:
2023-06-21 22:51:39 +03:00
let
dbName = "sample";
2023-06-21 23:09:47 +03:00
in
{
imports = [
inputs.services-flake.processComposeModules.default
];
2023-07-17 23:45:33 +03:00
services.postgres."pg1" = {
enable = true;
listen_addresses = "127.0.0.1";
initialDatabases = [
{
2023-06-21 22:51:39 +03:00
name = dbName;
schema = "${inputs.northwind}/northwind.sql";
}
];
};
2023-07-17 23:45:33 +03:00
services.postgres."pg2" = {
enable = true;
listen_addresses = "127.0.0.1";
port = 5433;
};
2023-06-21 22:51:39 +03:00
settings.processes.pgweb =
let
2023-07-17 23:45:33 +03:00
pgcfg = config.services.postgres.pg1;
2023-06-21 23:09:47 +03:00
in
{
2023-06-21 22:51:39 +03:00
environment.PGWEB_DATABASE_URL = "postgres://$USER@${pgcfg.listen_addresses}:${builtins.toString pgcfg.port}/${dbName}";
command = pkgs.pgweb;
2023-07-17 23:45:33 +03:00
depends_on."pg1".condition = "process_healthy";
2023-06-21 22:51:39 +03:00
};
# Set this attribute and get NixOS VM tests, as a flake check, for free.
testScript = ''
# FIXME: pgweb is still pending, but only in VM tests for some reason.
process_compose.wait_until(lambda procs:
2023-07-17 23:45:33 +03:00
procs["pg1"]["status"] == "Running"
)
2023-07-17 23:45:33 +03:00
machine.succeed("echo 'SELECT version();' | ${config.services.postgres.pg1.package}/bin/psql -h 127.0.0.1 -U tester ${dbName}")
'';
};
};
};
}