blob: 3155cc96a92c0ffcd8bcfacf3060aa7d13f857ca [file] [log] [blame]
Bartosz Stebel821b8392023-03-05 23:21:37 +01001{ config, pkgs, lib, ... }:
Serge Bazanski712a5dc2023-02-28 01:15:40 +00002
3with builtins;
Bartosz Stebel3b088732023-03-18 19:27:34 +01004let
5 postgresPkg = pkgs.postgresql_14;
6 numCPUs = 16;
Bartosz Stebel821b8392023-03-05 23:21:37 +01007in rec {
Serge Bazanski712a5dc2023-02-28 01:15:40 +00008 networking.hostName = "bc01n05";
9 # TODO: undefine fqdn and define domain after big nix change
10 hscloud.base.fqdn = "${networking.hostName}.hswaw.net";
11 #networking.domain = "hswaw.net";
12 system.stateVersion = "22.05";
Bartosz Stebel3b088732023-03-18 19:27:34 +010013 nix.maxJobs = numCPUs;
Serge Bazanski712a5dc2023-02-28 01:15:40 +000014
Bartosz Stebel821b8392023-03-05 23:21:37 +010015 ### zfs
16 # randomly generated
17 networking.hostId = "26dbfbcd";
18 boot.supportedFilesystems = [ "zfs" ];
19 boot.initrd.supportedFilesystems = [ "zfs" ];
20 services.zfs.trim.enable = true;
21
Serge Bazanski712a5dc2023-02-28 01:15:40 +000022 boot.loader.grub.device = "/dev/sda";
Bartosz Stebel821b8392023-03-05 23:21:37 +010023 fileSystems = {
24 "/" = {
25 device = "rpool/nixos/root";
26 fsType = lib.mkForce "zfs";
27 options = [ "X-mount.mkdir" ];
28 };
29 "/home" = {
30 device = "rpool/nixos/home";
31 fsType = "zfs";
32 options = [ "X-mount.mkdir" ];
33 };
34 "/var/lib/postgresql" = {
35 device = "rpool/postgres";
36 fsType = "zfs";
37 options = [ "X-mount.mkdir" ];
38 };
39 "/boot" = {
40 device = "/dev/disk/by-uuid/2a951c5d-0193-4ef3-9227-d8a5184cbd63";
41 fsType = "ext4";
42 };
Serge Bazanski712a5dc2023-02-28 01:15:40 +000043 };
44
45 hscloud.base = {
46 mgmtIf = "eno1";
47 ipAddr = "185.236.240.37";
48 ipAddrBits = 28;
49 gw = "185.236.240.33";
50 };
Bartosz Stebel821b8392023-03-05 23:21:37 +010051
Bartosz Stebel779727b2023-03-26 21:27:21 +020052 networking.firewall.allowedTCPPorts = [ config.services.postgresql.port ];
53
Bartosz Stebel821b8392023-03-05 23:21:37 +010054 environment.systemPackages = [postgresPkg];
55 services.postgresql = {
56 enable = true;
57 package = postgresPkg;
58 enableTCPIP = true;
59 initdbArgs = ["--encoding='UTF8'" "--lc-collate='C'" "--lc-ctype='C'"];
Bartosz Stebel3b088732023-03-18 19:27:34 +010060 settings = {
61 max_connections = 300;
Bartosz Stebel779727b2023-03-26 21:27:21 +020062 shared_buffers = "8GB";
63 temp_buffers = "128MB";
64 work_mem = "128MB";
Bartosz Stebel3b088732023-03-18 19:27:34 +010065 maintenance_work_mem = "258MB";
66 effective_io_concurrency = 10; # ssd, guess
67 maintenance_io_concurrency = 100; # ssd, guess
68 max_worker_processes = numCPUs;
69 max_parallel_workers = numCPUs;
70 max_parallel_maintenance_workers = 4;
71 wal_level = "logical";
72 wal_sync_method = "fsync"; # slightly faster (per pg_test_fsync) AND safer
73 full_page_writes = "off"; # partial writes impossible on zfs
74 wal_init_zero = "off"; # useless on CoW
75 wal_recycle = "off"; # same
76 random_page_cost = 2.0; # ssd, TODO maybe even lower?
77 };
Bartosz Stebel821b8392023-03-05 23:21:37 +010078 ensureDatabases = ["synapse" "mediarepo"];
79 ensureUsers = [
80 {
81 name = "synapse";
82 ensurePermissions = {
83 "DATABASE synapse" = "ALL PRIVILEGES";
84 };
85 }
86 {
87 name = "mediarepo";
88 ensurePermissions = {
89 "DATABASE mediarepo" = "ALL PRIVILEGES";
90 };
91 }
92 ];
Bartosz Stebel821b8392023-03-05 23:21:37 +010093 authentication = pkgs.lib.mkOverride 10 ''
Bartosz Stebel779727b2023-03-26 21:27:21 +020094 local all all trust
95 host all all 127.0.0.1/32 trust
96 host all all ::1/128 trust
97 host synapse,mediarepo synapse,mediarepo 185.236.240.0/24 scram-sha-256
Bartosz Stebel821b8392023-03-05 23:21:37 +010098 '';
99 };
Serge Bazanski712a5dc2023-02-28 01:15:40 +0000100}
101