]>
Commit | Line | Data |
---|---|---|
1 | { | |
2 | network = { | |
3 | description = "Immae's network"; | |
4 | enableRollback = true; | |
5 | }; | |
6 | ||
7 | eldiron = { config, pkgs, ... }: | |
8 | let mypkgs = import ./packages.nix; | |
9 | mylibs = import ../libs.nix; | |
10 | in | |
11 | { | |
12 | networking = { | |
13 | firewall = { | |
14 | enable = true; | |
15 | allowedTCPPorts = [ 22 80 443 3306 5432 ]; | |
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 | environment.systemPackages = [ | |
40 | pkgs.telnet | |
41 | pkgs.vim | |
42 | ]; | |
43 | ||
44 | security.acme.certs = { | |
45 | "eldiron" = { | |
46 | webroot = "/var/lib/acme/acme-challenge"; | |
47 | email = "ismael@bouya.org"; | |
48 | domain = "eldiron.immae.eu"; | |
49 | plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ]; | |
50 | postRun = '' | |
51 | systemctl reload httpd.service | |
52 | ''; | |
53 | extraDomains = { | |
54 | "db-1.immae.eu" = null; | |
55 | "tools.immae.eu" = null; | |
56 | "connexionswing.immae.eu" = null; | |
57 | "sandetludo.immae.eu" = null; | |
58 | }; | |
59 | }; | |
60 | # "connexionswing" = { | |
61 | # webroot = "/var/lib/acme/acme-challenge"; | |
62 | # email = "ismael@bouya.org"; | |
63 | # domain = "connexionswing.com"; | |
64 | # plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ]; | |
65 | # postRun = '' | |
66 | # systemctl reload httpd.service | |
67 | # ''; | |
68 | # extraDomains = { | |
69 | # "www.connexionswing.com" = null; | |
70 | # "sandetludo.com" = null; | |
71 | # "www.sandetludo.com" = null; | |
72 | # }; | |
73 | # }; | |
74 | }; | |
75 | ||
76 | services.ympd = mypkgs.ympd.config // { enable = true; }; | |
77 | ||
78 | services.phpfpm = { | |
79 | extraConfig = '' | |
80 | log_level = notice | |
81 | ''; | |
82 | poolConfigs = { | |
83 | adminer = mypkgs.adminer.phpFpm.pool; | |
84 | connexionswing_dev = mypkgs.connexionswing_dev.phpFpm.pool; | |
85 | connexionswing_prod = mypkgs.connexionswing_prod.phpFpm.pool; | |
86 | www = '' | |
87 | listen = /var/run/phpfpm/www.sock | |
88 | user = wwwrun | |
89 | group = wwwrun | |
90 | listen.owner = wwwrun | |
91 | listen.group = wwwrun | |
92 | pm = ondemand | |
93 | pm.max_children = 5 | |
94 | pm.process_idle_timeout = 60 | |
95 | ;php_admin_flag[log_errors] = on | |
96 | php_admin_value[open_basedir] = "/var/www" | |
97 | ''; | |
98 | }; | |
99 | }; | |
100 | ||
101 | system.activationScripts = { | |
102 | connexionswing_dev = mypkgs.connexionswing_dev.activationScript; | |
103 | connexionswing_prod = mypkgs.connexionswing_prod.activationScript; | |
104 | httpd = '' | |
105 | install -d -m 0755 /var/lib/acme/acme-challenge | |
106 | install -d -m 0755 /var/www | |
107 | ''; | |
108 | redis = '' | |
109 | mkdir -p /run/redis | |
110 | chown redis /run/redis | |
111 | ''; | |
112 | }; | |
113 | ||
114 | services.httpd = let | |
115 | withSSL = domain: { | |
116 | enableSSL = true; | |
117 | sslServerCert = "/var/lib/acme/${domain}/cert.pem"; | |
118 | sslServerKey = "/var/lib/acme/${domain}/key.pem"; | |
119 | sslServerChain = "/var/lib/acme/${domain}/fullchain.pem"; | |
120 | }; | |
121 | apacheConfig = { | |
122 | gzip = { | |
123 | modules = [ "deflate" "filter" ]; | |
124 | extraConfig = '' | |
125 | AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript | |
126 | ''; | |
127 | }; | |
128 | ldap = { | |
129 | modules = [ "ldap" "authnz_ldap" ]; | |
130 | extraConfig = assert mylibs.checkEnv "NIXOPS_HTTP_LDAP_PASSWORD"; '' | |
131 | <IfModule ldap_module> | |
132 | LDAPSharedCacheSize 500000 | |
133 | LDAPCacheEntries 1024 | |
134 | LDAPCacheTTL 600 | |
135 | LDAPOpCacheEntries 1024 | |
136 | LDAPOpCacheTTL 600 | |
137 | </IfModule> | |
138 | ||
139 | <Macro LDAPConnect> | |
140 | <IfModule authnz_ldap_module> | |
141 | AuthLDAPURL ldap://ldap.immae.eu:389/dc=immae,dc=eu | |
142 | AuthLDAPBindDN cn=httpd,ou=services,dc=immae,dc=eu | |
143 | AuthLDAPBindPassword "${builtins.getEnv "NIXOPS_HTTP_LDAP_PASSWORD"}" | |
144 | AuthType Basic | |
145 | AuthName "Authentification requise (Acces LDAP)" | |
146 | AuthBasicProvider ldap | |
147 | </IfModule> | |
148 | </Macro> | |
149 | ''; | |
150 | }; | |
151 | }; | |
152 | in rec { | |
153 | enable = true; | |
154 | logPerVirtualHost = true; | |
155 | multiProcessingModule = "worker"; | |
156 | adminAddr = "httpd@immae.eu"; | |
157 | # FIXME: http2 | |
158 | # FIXME: voir les autres modules: | |
159 | # authz_core_module | |
160 | # reqtimeout_module | |
161 | # http2_module | |
162 | # version_module | |
163 | # proxy_connect_module | |
164 | # proxy_ftp_module | |
165 | # proxy_scgi_module | |
166 | # proxy_ajp_module | |
167 | # proxy_balancer_module | |
168 | # proxy_express_module | |
169 | # lbmethod_byrequests_module | |
170 | # lbmethod_bytraffic_module | |
171 | # lbmethod_bybusyness_module | |
172 | # lbmethod_heartbeat_module | |
173 | ||
174 | extraModules = pkgs.lib.lists.unique ( | |
175 | mypkgs.adminer.apache.modules ++ | |
176 | mypkgs.connexionswing_dev.apache.modules ++ | |
177 | mypkgs.connexionswing_prod.apache.modules ++ | |
178 | mypkgs.ympd.apache.modules ++ | |
179 | pkgs.lib.lists.flatten (pkgs.lib.attrsets.mapAttrsToList (n: v: v.modules) apacheConfig) ++ | |
180 | [ "macro" ]); | |
181 | extraConfig = builtins.concatStringsSep "\n" | |
182 | (pkgs.lib.attrsets.mapAttrsToList (n: v: v.extraConfig) apacheConfig); | |
183 | virtualHosts = [ | |
184 | (withSSL "eldiron" // { | |
185 | listen = [ { ip = "*"; port = 443; } ]; | |
186 | hostName = "eldiron.immae.eu"; | |
187 | # FIXME: directory needs to exist | |
188 | documentRoot = "/var/www"; | |
189 | }) | |
190 | (withSSL "eldiron" // { | |
191 | listen = [ { ip = "*"; port = 443; } ]; | |
192 | hostName = "db-1.immae.eu"; | |
193 | documentRoot = null; | |
194 | extraConfig = builtins.concatStringsSep "\n" [ | |
195 | mypkgs.adminer.apache.vhostConf | |
196 | ]; | |
197 | }) | |
198 | (withSSL "eldiron" // { | |
199 | listen = [ { ip = "*"; port = 443; } ]; | |
200 | hostName = "tools.immae.eu"; | |
201 | documentRoot = null; | |
202 | extraConfig = builtins.concatStringsSep "\n" [ | |
203 | mypkgs.adminer.apache.vhostConf | |
204 | mypkgs.ympd.apache.vhostConf | |
205 | ]; | |
206 | }) | |
207 | (withSSL "eldiron" // { | |
208 | listen = [ { ip = "*"; port = 443; } ]; | |
209 | hostName = "connexionswing.immae.eu"; | |
210 | serverAliases = [ "sandetludo.immae.eu" ]; | |
211 | documentRoot = mypkgs.connexionswing_dev.webRoot; | |
212 | extraConfig = builtins.concatStringsSep "\n" [ | |
213 | mypkgs.connexionswing_dev.apache.vhostConf | |
214 | ]; | |
215 | }) | |
216 | { # Should go last, default fallback | |
217 | listen = [ { ip = "*"; port = 80; } ]; | |
218 | hostName = "redirectSSL"; | |
219 | serverAliases = [ "*" ]; | |
220 | enableSSL = false; | |
221 | documentRoot = "/var/lib/acme/acme-challenge"; | |
222 | extraConfig = '' | |
223 | RewriteEngine on | |
224 | RewriteCond "%{REQUEST_URI}" "!^/\.well-known" | |
225 | RewriteRule ^(.+) https://%{HTTP_HOST}$1 [R=301] | |
226 | # To redirect in specific "VirtualHost *:80", do | |
227 | # RedirectMatch 301 ^/((?!\.well-known.*$).*)$ https://host/$1 | |
228 | # rather than rewrite | |
229 | ''; | |
230 | } | |
231 | ]; | |
232 | }; | |
233 | ||
234 | security.pam.services = let | |
235 | pam_ldap = pkgs.pam_ldap; | |
236 | pam_ldap_mysql = assert mylibs.checkEnv "NIXOPS_MYSQL_PAM_PASSWORD"; | |
237 | pkgs.writeText "mysql.conf" '' | |
238 | host ldap.immae.eu | |
239 | base dc=immae,dc=eu | |
240 | binddn cn=mysql,cn=pam,ou=services,dc=immae,dc=eu | |
241 | bindpw ${builtins.getEnv "NIXOPS_MYSQL_PAM_PASSWORD"} | |
242 | pam_filter memberOf=cn=users,cn=mysql,cn=pam,ou=services,dc=immae,dc=eu | |
243 | ''; | |
244 | in [ | |
245 | { | |
246 | name = "mysql"; | |
247 | text = '' | |
248 | # https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/ | |
249 | auth required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql} | |
250 | account required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql} | |
251 | ''; | |
252 | } | |
253 | ]; | |
254 | ||
255 | # FIXME: backup | |
256 | services.redis = rec { | |
257 | enable = true; | |
258 | bind = "127.0.0.1"; | |
259 | unixSocket = "/run/redis/redis.sock"; | |
260 | extraConfig = '' | |
261 | unixsocketperm 777 | |
262 | maxclients 1024 | |
263 | ''; | |
264 | }; | |
265 | ||
266 | # FIXME: initial sync | |
267 | # FIXME: backup | |
268 | # FIXME: restart after pam | |
269 | # FIXME: pam access doesn’t work (because of php module) | |
270 | # FIXME: ssl | |
271 | services.mysql = rec { | |
272 | enable = true; | |
273 | package = pkgs.mariadb.overrideAttrs(old: rec { | |
274 | cmakeFlags = old.cmakeFlags ++ [ "-DWITH_AUTHENTICATION_PAM=ON" ]; | |
275 | buildInputs = old.buildInputs ++ [ pkgs.pam ]; | |
276 | }); | |
277 | }; | |
278 | ||
279 | # FIXME: initial sync | |
280 | # FIXME: backup | |
281 | # FIXME: ssl | |
282 | services.postgresql = rec { | |
283 | enable = true; | |
284 | package = pkgs.postgresql100.overrideAttrs(old: rec { | |
285 | passthru = old.passthru // { psqlSchema = "11.0"; }; | |
286 | name = "postgresql-11.1"; | |
287 | src = pkgs.fetchurl { | |
288 | url = "mirror://postgresql/source/v11.1/${name}.tar.bz2"; | |
289 | sha256 = "026v0sicsh7avzi45waf8shcbhivyxmi7qgn9fd1x0vl520mx0ch"; | |
290 | }; | |
291 | }); | |
292 | enableTCPIP = true; | |
293 | extraConfig = '' | |
294 | max_connections = 100 | |
295 | wal_level = logical | |
296 | shared_buffers = 128MB | |
297 | max_wal_size = 1GB | |
298 | min_wal_size = 80MB | |
299 | log_timezone = 'Europe/Paris' | |
300 | datestyle = 'iso, mdy' | |
301 | timezone = 'Europe/Paris' | |
302 | lc_messages = 'en_US.UTF-8' | |
303 | lc_monetary = 'en_US.UTF-8' | |
304 | lc_numeric = 'en_US.UTF-8' | |
305 | lc_time = 'en_US.UTF-8' | |
306 | default_text_search_config = 'pg_catalog.english' | |
307 | # ssl = on | |
308 | # ssl_cert_file = '/var/lib/acme/eldiron/fullchain.pem' | |
309 | # ssl_key_file = '/var/lib/acme/eldiron/key.pem' | |
310 | ''; | |
311 | authentication = '' | |
312 | local all postgres ident | |
313 | local all all md5 | |
314 | host all all 178.33.252.96/32 md5 | |
315 | host all all 188.165.209.148/32 md5 | |
316 | #host all all all pam | |
317 | ''; | |
318 | }; | |
319 | }; | |
320 | } |