Files
cyper-rpi/hosts/cyper-pi-1/postgrest.nix

93 lines
2.3 KiB
Nix

{
pkgs,
...
}:
{
# PostgREST service
systemd.services = {
postgrest = {
description = "PostgREST - PostgreSQL REST API";
after = [
"postgresql.service"
"network.target"
];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
ExecStart = "${pkgs.postgrest}/bin/postgrest /etc/postgrest/postgrest.conf";
User = "postgrest";
Restart = "on-failure";
RestartSec = 5;
};
};
# PostgREST service for learnlytics database
postgrest-learnlytics = {
description = "PostgREST - Learnlytics API";
after = [
"postgresql.service"
"network.target"
];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
ExecStart = "${pkgs.postgrest}/bin/postgrest /etc/postgrest/postgrest-learnlytics.conf";
User = "postgrest";
Restart = "on-failure";
RestartSec = 5;
};
};
};
# Create postgrest user
users = {
users.postgrest = {
isSystemUser = true;
group = "postgrest";
};
groups.postgrest = { };
};
# PostgREST configuration file
environment.etc = {
"postgrest/postgrest.conf".text = ''
db-uri = "postgres://postgres:1P2h3i4lon@127.0.0.1:5432/postgres"
db-schema = "public"
db-anon-role = "web_anon"
server-host = "0.0.0.0"
server-port = 3000
server-proxy-uri = "http://192.168.2.200:3000"
jwt-secret = "no7WwM0xJa/Yzn5o4IZHG4oBNSShl4JRPZOcmhvnqFw="
server-cors-allowed-origins = "*"
openapi-server-proxy-uri = "http://192.168.2.200:3000"
'';
# PostgREST configuration for learnlytics database
"postgrest/postgrest-learnlytics.conf".text = ''
db-uri = "postgres://postgres:1P2h3i4lon@127.0.0.1:5432/learnlytics"
db-schema = "public"
db-anon-role = "web_anon"
server-host = "0.0.0.0"
server-port = 3001
server-proxy-uri = "http://192.168.2.200:3001"
jwt-secret = "dnjudqZC0Fby2DEo3Xt2nY98KlHxxqT7NWvLk5aKmew="
server-cors-allowed-origins = "*"
'';
};
# Open firewall port for PostgREST
networking.firewall.allowedTCPPorts = [
3000
3001
];
# Include postgrest in system packages
environment.systemPackages = with pkgs; [
postgrest
];
}