summary refs log tree commit diff
path: root/host/Spacebar-postgres/configuration.nix
blob: b40fd3af53fba582aa935eca5947e19f38ac885b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{ config, pkgs, lib, ... }:

{
  imports =
    [
      ../../modules/base.nix
    ];

  networking = {
    hostName = "Spacebar-postgres";
    interfaces.ens18.ipv4.addresses = [ { 
      address = "192.168.1.4";
      prefixLength = 24;
    } ];
    interfaces.ens19.ipv4.addresses = [ {
      address = "10.10.11.4";
      prefixLength = 16;
    } ];
  };
  
  systemd.tmpfiles.rules = [  "d /data/pg 0750 postgres postgres" ];

  services.postgresql = {
    enable = true;
    package = pkgs.postgresql_14;
    enableTCPIP = true;
    authentication = pkgs.lib.mkOverride 10 ''
      # TYPE, DATABASE, USER, ADDRESS, METHOD
      local all all trust
      host all all 127.0.0.1/32 trust
      host all all ::1/128 trust
      host matrix-synapse-spacebar-chat matrix-synapse-spacebar-chat 192.168.1.5/32 trust
      host all all 0.0.0.0/0 md5
    '';
    initialScript = pkgs.writeText "backend-initScript" ''
      CREATE ROLE matrix-synapse-spacebar-chat WITH LOGIN PASSWORD '${pkgs.postgresql_14}' CREATEDB;
      CREATE DATABASE matrix-synapse-spacebar-chat;
      GRANT ALL PRIVILEGES ON DATABASE matrix-synapse-spacebar-chat TO matrix-synapse-spacebar-chat;
    '';
    dataDir = "/data/pg";
    settings = {
      "max_connections" = "100";
      "shared_buffers" = "128MB";
      "max_wal_size" = "1GB";
      "min_wal_size" = "80MB";
    };
  };

  system.stateVersion = "22.11"; # DO NOT EDIT!
}