diff options
Diffstat (limited to 'systems/zoldene/database.nix')
-rw-r--r-- | systems/zoldene/database.nix | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/systems/zoldene/database.nix b/systems/zoldene/database.nix new file mode 100644 index 0000000..2eb6cd9 --- /dev/null +++ b/systems/zoldene/database.nix | |||
@@ -0,0 +1,50 @@ | |||
1 | { pkgs, config, lib, nodes, ... }: | ||
2 | let | ||
3 | psqlVersion = pkgs.postgresql_16.psqlSchema; | ||
4 | in | ||
5 | { | ||
6 | disko.devices.zpool.zfast.datasets."root/persist/var/lib/postgresql" = | ||
7 | { type = "zfs_fs"; mountpoint = "/persist/zfast/var/lib/postgresql"; options.mountpoint = "legacy"; }; | ||
8 | disko.devices.zpool.zfast.datasets."root/persist/var/lib/postgresql/${psqlVersion}" = | ||
9 | { type = "zfs_fs"; mountpoint = "/persist/zfast/var/lib/postgresql/${psqlVersion}"; options.mountpoint = "legacy"; }; | ||
10 | environment.persistence."/persist/zfast".directories = [ | ||
11 | { | ||
12 | directory = "/var/lib/postgresql"; | ||
13 | user = config.users.users.postgres.name; | ||
14 | group = config.users.users.postgres.group; | ||
15 | mode = "0755"; | ||
16 | } | ||
17 | { | ||
18 | directory = "/var/lib/postgresql/${psqlVersion}"; | ||
19 | user = config.users.users.postgres.name; | ||
20 | group = config.users.users.postgres.group; | ||
21 | mode = "0755"; | ||
22 | } | ||
23 | ]; | ||
24 | systemd.services.postgresql.after = [ | ||
25 | "var-lib-postgresql.mount" | ||
26 | "var-lib-postgresql-16.mount" | ||
27 | "persist-zfast-var-lib-postgresql.mount" | ||
28 | "persist-zfast-var-lib-postgresql-16.mount" | ||
29 | ]; | ||
30 | systemd.services.postgresql.unitConfig = { | ||
31 | BindsTo = [ | ||
32 | "var-lib-postgresql.mount" | ||
33 | "var-lib-postgresql-16.mount" | ||
34 | "persist-zfast-var-lib-postgresql.mount" | ||
35 | "persist-zfast-var-lib-postgresql-16.mount" | ||
36 | ]; | ||
37 | }; | ||
38 | |||
39 | services.postgresql = { | ||
40 | enable = true; | ||
41 | package = pkgs.postgresql_16; | ||
42 | settings.listen_addresses = lib.mkForce (builtins.concatStringsSep "," [ | ||
43 | "localhost" | ||
44 | config.hostEnv.wireguard.ip | ||
45 | ]); | ||
46 | authentication = '' | ||
47 | host replication postgres ${nodes.backup-2.config.hostEnv.wireguard.ip}/32 ident | ||
48 | ''; | ||
49 | }; | ||
50 | } | ||