]>
Commit | Line | Data |
---|---|---|
a1bb33c4 IB |
1 | { |
2 | network = { | |
3 | description = "Immae's network"; | |
4 | enableRollback = true; | |
5 | }; | |
6 | ||
ab5d04b8 IB |
7 | eldiron = { config, pkgs, ... }: |
8 | let mypkgs = import ./packages.nix; | |
6cd8d6ce | 9 | mylibs = import ../libs.nix; |
ab5d04b8 IB |
10 | in |
11 | { | |
a1bb33c4 IB |
12 | networking = { |
13 | firewall = { | |
14 | enable = true; | |
dedf591d | 15 | allowedTCPPorts = [ 22 80 443 3306 5432 ]; |
a1bb33c4 IB |
16 | }; |
17 | }; | |
18 | ||
19 | deployment = { | |
20 | targetEnv = "hetzner"; | |
21 | hetzner = { | |
22 | #robotUser = "defined in HETZNER_ROBOT_USER"; | |
23 | #robotPass = "defined in HETZNER_ROBOT_PASS"; | |
24 | mainIPv4 = "176.9.151.89"; | |
25 | partitions = '' | |
26 | clearpart --all --initlabel --drives=sda,sdb | |
27 | ||
28 | part swap1 --recommended --label=swap1 --fstype=swap --ondisk=sda | |
29 | part swap2 --recommended --label=swap2 --fstype=swap --ondisk=sdb | |
30 | ||
31 | part raid.1 --grow --ondisk=sda | |
32 | part raid.2 --grow --ondisk=sdb | |
33 | ||
34 | raid / --level=1 --device=md0 --fstype=ext4 --label=root raid.1 raid.2 | |
35 | ''; | |
36 | }; | |
37 | }; | |
38 | ||
39 | # FIXME: how to run it? currently set as timer | |
40 | security.acme.certs = { | |
41 | "eldiron" = { | |
42 | webroot = "/var/lib/acme/acme-challenge"; | |
43 | email = "ismael@bouya.org"; | |
44 | domain = "eldiron.immae.eu"; | |
e379fd29 IB |
45 | plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ]; |
46 | postRun = '' | |
47 | "systemctl reload httpd.service" | |
48 | ''; | |
a1bb33c4 IB |
49 | extraDomains = { |
50 | "db-1.immae.eu" = null; | |
e379fd29 | 51 | "tools.immae.eu" = null; |
65fe7543 IB |
52 | "connexionswing.immae.eu" = null; |
53 | "sandetludo.immae.eu" = null; | |
a1bb33c4 IB |
54 | }; |
55 | }; | |
56 | }; | |
57 | ||
a05f8abe IB |
58 | services.ympd = mypkgs.ympd.config // { enable = true; }; |
59 | ||
58d1a782 IB |
60 | # FIXME: open_basedir |
61 | services.phpfpm = { | |
62 | extraConfig = '' | |
63 | log_level = notice | |
64 | ''; | |
65 | poolConfigs = { | |
27e22b76 | 66 | adminer = mypkgs.adminer.phpFpm.pool; |
65fe7543 | 67 | connexionswing_dev = mypkgs.connexionswing_dev.phpFpm.pool; |
58d1a782 IB |
68 | www = '' |
69 | listen = /var/run/phpfpm/www.sock | |
70 | user = wwwrun | |
71 | group = wwwrun | |
72 | listen.owner = wwwrun | |
73 | listen.group = wwwrun | |
74 | pm = ondemand | |
75 | pm.max_children = 5 | |
76 | pm.process_idle_timeout = 60 | |
77 | ;php_admin_flag[log_errors] = on | |
78 | php_admin_value[open_basedir] = "/var/www" | |
79 | ''; | |
80 | }; | |
81 | }; | |
82 | ||
65fe7543 IB |
83 | system.activationScripts = { |
84 | connexionswing_dev = mypkgs.connexionswing_dev.activationScript; | |
5dd28b43 IB |
85 | httpd = '' |
86 | install -d -m 0755 /var/lib/acme/acme-challenge | |
87 | install -d -m 0755 /var/www | |
88 | ''; | |
65fe7543 IB |
89 | }; |
90 | ||
58d1a782 IB |
91 | services.httpd = let |
92 | withSSL = domain: { | |
93 | enableSSL = true; | |
5dd28b43 | 94 | sslServerCert = "/var/lib/acme/${domain}/cert.pem"; |
58d1a782 IB |
95 | sslServerKey = "/var/lib/acme/${domain}/key.pem"; |
96 | sslServerChain = "/var/lib/acme/${domain}/fullchain.pem"; | |
97 | }; | |
98 | in rec { | |
a1bb33c4 | 99 | enable = true; |
58d1a782 IB |
100 | logPerVirtualHost = true; |
101 | multiProcessingModule = "worker"; | |
102 | adminAddr = "httpd@immae.eu"; | |
25fd1d16 IB |
103 | # FIXME: http2 |
104 | extraModules = pkgs.lib.lists.unique ( | |
105 | mypkgs.adminer.apache.modules ++ | |
65fe7543 | 106 | mypkgs.connexionswing_dev.apache.modules ++ |
25fd1d16 IB |
107 | [ |
108 | "macro" | |
109 | "ldap" | |
110 | "authnz_ldap" | |
111 | ]); | |
6cd8d6ce | 112 | extraConfig = assert mylibs.checkEnv "NIXOPS_HTTP_LDAP_PASSWORD"; '' |
95413adf IB |
113 | <IfModule ldap_module> |
114 | LDAPSharedCacheSize 500000 | |
115 | LDAPCacheEntries 1024 | |
116 | LDAPCacheTTL 600 | |
117 | LDAPOpCacheEntries 1024 | |
118 | LDAPOpCacheTTL 600 | |
119 | </IfModule> | |
120 | ||
121 | <Macro LDAPConnect> | |
122 | <IfModule authnz_ldap_module> | |
123 | AuthLDAPURL ldap://ldap.immae.eu:389/dc=immae,dc=eu | |
124 | AuthLDAPBindDN cn=httpd,ou=services,dc=immae,dc=eu | |
125 | AuthLDAPBindPassword "${builtins.getEnv "NIXOPS_HTTP_LDAP_PASSWORD"}" | |
126 | AuthType Basic | |
127 | AuthName "Authentification requise (Acces LDAP)" | |
128 | AuthBasicProvider ldap | |
129 | </IfModule> | |
130 | </Macro> | |
131 | ''; | |
58d1a782 IB |
132 | virtualHosts = [ |
133 | (withSSL "eldiron" // { | |
134 | listen = [ { ip = "*"; port = 443; } ]; | |
135 | hostName = "eldiron.immae.eu"; | |
136 | # FIXME: directory needs to exist | |
137 | documentRoot = "/var/www"; | |
138 | }) | |
139 | (withSSL "eldiron" // { | |
140 | listen = [ { ip = "*"; port = 443; } ]; | |
141 | hostName = "db-1.immae.eu"; | |
142 | documentRoot = null; | |
27e22b76 | 143 | extraConfig = builtins.concatStringsSep "\n" [ |
1bb2ff2c | 144 | mypkgs.adminer.apache.vhostConf |
27e22b76 | 145 | ]; |
58d1a782 | 146 | }) |
e379fd29 IB |
147 | (withSSL "eldiron" // { |
148 | listen = [ { ip = "*"; port = 443; } ]; | |
149 | hostName = "tools.immae.eu"; | |
150 | documentRoot = null; | |
151 | extraConfig = builtins.concatStringsSep "\n" [ | |
1bb2ff2c | 152 | mypkgs.adminer.apache.vhostConf |
a05f8abe | 153 | mypkgs.ympd.apache.vhostConf |
e379fd29 IB |
154 | ]; |
155 | }) | |
65fe7543 IB |
156 | (withSSL "eldiron" // { |
157 | listen = [ { ip = "*"; port = 443; } ]; | |
158 | hostName = "connexionswing.immae.eu"; | |
159 | serverAliases = [ "sandetludo.immae.eu" ]; | |
160 | documentRoot = mypkgs.connexionswing_dev.webRoot; | |
161 | extraConfig = builtins.concatStringsSep "\n" [ | |
162 | mypkgs.connexionswing_dev.apache.vhostConf | |
163 | ]; | |
164 | }) | |
58d1a782 IB |
165 | { # Should go last, default fallback |
166 | listen = [ { ip = "*"; port = 80; } ]; | |
167 | hostName = "redirectSSL"; | |
168 | serverAliases = [ "*" ]; | |
169 | enableSSL = false; | |
170 | # FIXME: directory needs to exist | |
171 | documentRoot = "/var/lib/acme/acme-challenge"; | |
172 | extraConfig = '' | |
173 | RewriteEngine on | |
174 | RewriteCond "%{REQUEST_URI}" "!^/\.well-known" | |
175 | RewriteRule ^(.+) https://%{HTTP_HOST}$1 [R=301] | |
176 | # To redirect in specific "VirtualHost *:80", do | |
177 | # RedirectMatch 301 ^/((?!\.well-known.*$).*)$ https://host/$1 | |
178 | # rather than rewrite | |
179 | ''; | |
180 | } | |
181 | ]; | |
182 | }; | |
183 | ||
dedf591d IB |
184 | security.pam.services = let |
185 | pam_ldap = pkgs.pam_ldap; | |
6cd8d6ce IB |
186 | pam_ldap_mysql = assert mylibs.checkEnv "NIXOPS_MYSQL_PAM_PASSWORD"; |
187 | pkgs.writeText "mysql.conf" '' | |
dedf591d IB |
188 | host ldap.immae.eu |
189 | base dc=immae,dc=eu | |
190 | binddn cn=mysql,cn=pam,ou=services,dc=immae,dc=eu | |
191 | bindpw ${builtins.getEnv "NIXOPS_MYSQL_PAM_PASSWORD"} | |
192 | pam_filter memberOf=cn=users,cn=mysql,cn=pam,ou=services,dc=immae,dc=eu | |
193 | ''; | |
194 | in [ | |
195 | { | |
196 | name = "mysql"; | |
197 | text = '' | |
198 | # https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/ | |
199 | auth required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql} | |
200 | account required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql} | |
201 | ''; | |
202 | } | |
203 | ]; | |
204 | ||
205 | # FIXME: initial sync | |
206 | # FIXME: backup | |
207 | # FIXME: restart after pam | |
208 | # FIXME: pam access doesn’t work (because of php module) | |
27e22b76 | 209 | # FIXME: ssl |
dedf591d IB |
210 | services.mysql = rec { |
211 | enable = true; | |
212 | package = pkgs.mariadb.overrideAttrs(old: rec { | |
213 | cmakeFlags = old.cmakeFlags ++ [ "-DWITH_AUTHENTICATION_PAM=ON" ]; | |
214 | buildInputs = old.buildInputs ++ [ pkgs.pam ]; | |
215 | }); | |
216 | }; | |
217 | ||
a1bb33c4 | 218 | # FIXME: initial sync |
dedf591d | 219 | # FIXME: backup |
27e22b76 | 220 | # FIXME: ssl |
a1bb33c4 IB |
221 | services.postgresql = rec { |
222 | enable = true; | |
223 | package = pkgs.postgresql100.overrideAttrs(old: rec { | |
224 | passthru = old.passthru // { psqlSchema = "11.0"; }; | |
225 | name = "postgresql-11.1"; | |
226 | src = pkgs.fetchurl { | |
227 | url = "mirror://postgresql/source/v11.1/${name}.tar.bz2"; | |
228 | sha256 = "026v0sicsh7avzi45waf8shcbhivyxmi7qgn9fd1x0vl520mx0ch"; | |
229 | }; | |
230 | }); | |
231 | enableTCPIP = true; | |
232 | extraConfig = '' | |
233 | max_connections = 100 | |
234 | wal_level = logical | |
235 | shared_buffers = 128MB | |
236 | max_wal_size = 1GB | |
237 | min_wal_size = 80MB | |
238 | log_timezone = 'Europe/Paris' | |
239 | datestyle = 'iso, mdy' | |
240 | timezone = 'Europe/Paris' | |
241 | lc_messages = 'en_US.UTF-8' | |
242 | lc_monetary = 'en_US.UTF-8' | |
243 | lc_numeric = 'en_US.UTF-8' | |
244 | lc_time = 'en_US.UTF-8' | |
245 | default_text_search_config = 'pg_catalog.english' | |
246 | # ssl = on | |
247 | # ssl_cert_file = '/var/lib/acme/eldiron/fullchain.pem' | |
248 | # ssl_key_file = '/var/lib/acme/eldiron/key.pem' | |
249 | ''; | |
250 | authentication = '' | |
251 | local all postgres ident | |
252 | local all all md5 | |
253 | host all all 178.33.252.96/32 md5 | |
254 | host all all 188.165.209.148/32 md5 | |
255 | #host all all all pam | |
256 | ''; | |
257 | }; | |
258 | }; | |
259 | } |