Add postgrest

This commit is contained in:
Sridhar Ratnakumar 2021-04-10 16:44:46 -04:00
parent d0851959ca
commit 3a57cfa449
3 changed files with 51 additions and 1 deletions

45
features/postgrest.nix Normal file
View file

@ -0,0 +1,45 @@
{ pkgs, ... }:
let
postgrest = pkgs.haskellPackages.postgrest;
in
{
# PostgreSQL itself
services.postgresql = {
enable = true;
package = pkgs.postgresql_12;
enableTCPIP = false;
# https://nixos.wiki/wiki/PostgreSQL
authentication = pkgs.lib.mkOverride 10
''
# Unix domain socket
local all all trust
# TCP/IP connections from loopback only
host all all ::1/128 trust
'';
initialScript = pkgs.writeText "backend-initScript" ''
CREATE ROLE nixcloud WITH LOGIN PASSWORD 'nixcloud' CREATEDB;
CREATE DATABASE nixcloud;
GRANT ALL PRIVILEGES ON DATABASE nixcloud TO nixcloud;
'';
};
# PostgREST as systemd service
systemd.services.postgrest = {
enable = true;
description = "PostgREST daemon";
after = [ "postgresql.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart =
let pgrstConf = pkgs.writeText "pgrst.conf" ''
db-uri = "postgres://postgres@localhost/postgres"
db-schema = "public"
db-anon-role = "postgres"
server-port = 7000
'';
in
"${postgrest}/bin/postgrest ${pgrstConf}";
Restart = "always";
};
};
}

View file

@ -17,7 +17,8 @@
modules = ([
# System configuration
configurationNix
# ./features/virtualization.nix
# Features common to all of my machines
./features/passwordstore.nix
./features/syncthing.nix
./features/email
@ -44,6 +45,8 @@
[
inputs.nixos-hardware.nixosModules.lenovo-thinkpad-p53
./features/desktopish
# ./features/virtualization.nix
./features/postgrest.nix
];
nixosConfigurations.x1c7 = mkHomeMachine
./hosts/x1c7.nix

View file

@ -84,6 +84,8 @@
obsidian
signal-desktop
ripgrep
fzf
htop
];