diff options
Diffstat (limited to 'nixops/modules/databases/postgresql.nix')
-rw-r--r-- | nixops/modules/databases/postgresql.nix | 120 |
1 files changed, 0 insertions, 120 deletions
diff --git a/nixops/modules/databases/postgresql.nix b/nixops/modules/databases/postgresql.nix deleted file mode 100644 index de0820f..0000000 --- a/nixops/modules/databases/postgresql.nix +++ /dev/null | |||
@@ -1,120 +0,0 @@ | |||
1 | { lib, pkgs, config, myconfig, ... }: | ||
2 | let | ||
3 | cfg = config.services.myDatabases; | ||
4 | in { | ||
5 | options.services.myDatabases = { | ||
6 | postgresql = { | ||
7 | enable = lib.mkOption { | ||
8 | default = cfg.enable; | ||
9 | example = true; | ||
10 | description = "Whether to enable postgresql database"; | ||
11 | type = lib.types.bool; | ||
12 | }; | ||
13 | }; | ||
14 | }; | ||
15 | |||
16 | config = lib.mkIf cfg.enable { | ||
17 | nixpkgs.overlays = [ (self: super: rec { | ||
18 | postgresql = self.postgresql_11_custom; | ||
19 | }) ]; | ||
20 | |||
21 | networking.firewall.allowedTCPPorts = [ 5432 ]; | ||
22 | |||
23 | security.acme.certs."postgresql" = config.services.myCertificates.certConfig // { | ||
24 | user = "postgres"; | ||
25 | group = "postgres"; | ||
26 | plugins = [ "fullchain.pem" "key.pem" "account_key.json" ]; | ||
27 | domain = "db-1.immae.eu"; | ||
28 | postRun = '' | ||
29 | systemctl reload postgresql.service | ||
30 | ''; | ||
31 | }; | ||
32 | |||
33 | systemd.services.postgresql.serviceConfig.SupplementaryGroups = "keys"; | ||
34 | systemd.services.postgresql.serviceConfig.RuntimeDirectory = "postgresql"; | ||
35 | services.postgresql = rec { | ||
36 | enable = cfg.postgresql.enable; | ||
37 | package = pkgs.postgresql; | ||
38 | enableTCPIP = true; | ||
39 | extraConfig = '' | ||
40 | max_connections = 100 | ||
41 | wal_level = logical | ||
42 | shared_buffers = 512MB | ||
43 | work_mem = 10MB | ||
44 | max_wal_size = 1GB | ||
45 | min_wal_size = 80MB | ||
46 | log_timezone = 'Europe/Paris' | ||
47 | datestyle = 'iso, mdy' | ||
48 | timezone = 'Europe/Paris' | ||
49 | lc_messages = 'en_US.UTF-8' | ||
50 | lc_monetary = 'en_US.UTF-8' | ||
51 | lc_numeric = 'en_US.UTF-8' | ||
52 | lc_time = 'en_US.UTF-8' | ||
53 | default_text_search_config = 'pg_catalog.english' | ||
54 | ssl = on | ||
55 | ssl_cert_file = '/var/lib/acme/postgresql/fullchain.pem' | ||
56 | ssl_key_file = '/var/lib/acme/postgresql/key.pem' | ||
57 | ''; | ||
58 | authentication = '' | ||
59 | local all postgres ident | ||
60 | local all all md5 | ||
61 | hostssl all all 188.165.209.148/32 md5 | ||
62 | hostssl all all 178.33.252.96/32 md5 | ||
63 | hostssl all all all pam | ||
64 | hostssl replication backup-1 2001:41d0:302:1100::9:e5a9/128 pam pamservice=postgresql_replication | ||
65 | hostssl replication backup-1 54.37.151.137/32 pam pamservice=postgresql_replication | ||
66 | ''; | ||
67 | }; | ||
68 | |||
69 | secrets.keys = [ | ||
70 | { | ||
71 | dest = "postgresql/pam"; | ||
72 | permissions = "0400"; | ||
73 | group = "postgres"; | ||
74 | user = "postgres"; | ||
75 | text = with myconfig.env.databases.postgresql.pam; '' | ||
76 | host ${myconfig.env.ldap.host} | ||
77 | base ${myconfig.env.ldap.base} | ||
78 | binddn ${dn} | ||
79 | bindpw ${password} | ||
80 | pam_filter ${filter} | ||
81 | ssl start_tls | ||
82 | ''; | ||
83 | } | ||
84 | { | ||
85 | dest = "postgresql/pam_replication"; | ||
86 | permissions = "0400"; | ||
87 | group = "postgres"; | ||
88 | user = "postgres"; | ||
89 | text = '' | ||
90 | host ${myconfig.env.ldap.host} | ||
91 | base ${myconfig.env.ldap.base} | ||
92 | binddn ${myconfig.env.ldap.host_dn} | ||
93 | bindpw ${myconfig.env.ldap.password} | ||
94 | pam_login_attribute cn | ||
95 | ssl start_tls | ||
96 | ''; | ||
97 | } | ||
98 | ]; | ||
99 | |||
100 | security.pam.services = let | ||
101 | pam_ldap = "${pkgs.pam_ldap}/lib/security/pam_ldap.so"; | ||
102 | in [ | ||
103 | { | ||
104 | name = "postgresql"; | ||
105 | text = '' | ||
106 | auth required ${pam_ldap} config=/var/secrets/postgresql/pam | ||
107 | account required ${pam_ldap} config=/var/secrets/postgresql/pam | ||
108 | ''; | ||
109 | } | ||
110 | { | ||
111 | name = "postgresql_replication"; | ||
112 | text = '' | ||
113 | auth required ${pam_ldap} config=/var/secrets/postgresql/pam_replication | ||
114 | account required ${pam_ldap} config=/var/secrets/postgresql/pam_replication | ||
115 | ''; | ||
116 | } | ||
117 | ]; | ||
118 | }; | ||
119 | } | ||
120 | |||