]>
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 | ||
66b5bbf6 IB |
39 | environment.systemPackages = let |
40 | # FIXME: move it to nextcloud | |
41 | occ = pkgs.writeScriptBin "nextcloud-occ" '' | |
42 | #! ${pkgs.stdenv.shell} | |
43 | cd ${mypkgs.nextcloud.webRoot} | |
44 | NEXTCLOUD_CONFIG_DIR="${mypkgs.nextcloud.webRoot}/config" \ | |
45 | exec \ | |
46 | ${config.services.phpfpm.phpPackage}/bin/php \ | |
47 | -c ${config.services.phpfpm.phpPackage}/etc/php.ini \ | |
48 | occ $* | |
49 | ''; | |
50 | in [ | |
ce6ee3b8 IB |
51 | pkgs.telnet |
52 | pkgs.vim | |
66b5bbf6 | 53 | occ |
ce6ee3b8 IB |
54 | ]; |
55 | ||
a1bb33c4 IB |
56 | security.acme.certs = { |
57 | "eldiron" = { | |
58 | webroot = "/var/lib/acme/acme-challenge"; | |
59 | email = "ismael@bouya.org"; | |
60 | domain = "eldiron.immae.eu"; | |
e379fd29 IB |
61 | plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ]; |
62 | postRun = '' | |
e273ef92 | 63 | systemctl reload httpd.service |
e379fd29 | 64 | ''; |
a1bb33c4 IB |
65 | extraDomains = { |
66 | "db-1.immae.eu" = null; | |
e379fd29 | 67 | "tools.immae.eu" = null; |
65fe7543 IB |
68 | "connexionswing.immae.eu" = null; |
69 | "sandetludo.immae.eu" = null; | |
66b5bbf6 | 70 | "cloud.immae.eu" = null; |
a1bb33c4 IB |
71 | }; |
72 | }; | |
e273ef92 IB |
73 | # "connexionswing" = { |
74 | # webroot = "/var/lib/acme/acme-challenge"; | |
75 | # email = "ismael@bouya.org"; | |
76 | # domain = "connexionswing.com"; | |
77 | # plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ]; | |
78 | # postRun = '' | |
79 | # systemctl reload httpd.service | |
80 | # ''; | |
81 | # extraDomains = { | |
82 | # "www.connexionswing.com" = null; | |
83 | # "sandetludo.com" = null; | |
84 | # "www.sandetludo.com" = null; | |
85 | # }; | |
86 | # }; | |
a1bb33c4 IB |
87 | }; |
88 | ||
5566d26d IB |
89 | services.openssh.extraConfig = '' |
90 | AuthorizedKeysCommand /etc/ssh/ldap_authorized_keys | |
91 | AuthorizedKeysCommandUser nobody | |
92 | ''; | |
93 | ||
94 | # FIXME: after initial install, need to | |
95 | # (1) copy rc file (adjust gitolite_ldap_groups.sh) | |
96 | # (2) (mark old readonly and) sync repos except gitolite-admin | |
97 | # rsync -av --exclude=gitolite-admin.git old:/var/lib/gitolite/repositories /var/lib/gitolite/ | |
98 | # chown -R gitolite:gitolite /var/lib/gitolite | |
99 | # (3) push force the gitolite-admin to new location (from external point) | |
100 | # Don't use an existing key, it will take precedence over | |
101 | # gitolite-admin | |
102 | # (4) su -u gitolite gitolite setup | |
103 | services.gitolite = { | |
104 | enable = true; | |
105 | # FIXME: key from ./ssh | |
106 | adminPubkey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDXqRbiHw7QoHADNIEuo4nUT9fSOIEBMdJZH0bkQAxXyJFyCM1IMz0pxsHV0wu9tdkkr36bPEUj2aV5bkYLBN6nxcV2Y49X8bjOSCPfx3n6Own1h+NeZVBj4ZByrFmqCbTxUJIZ2bZKcWOFncML39VmWdsVhNjg0X4NBBehqXRIKr2gt3E/ESAxTYJFm0BnU0baciw9cN0bsRGqvFgf5h2P48CIAfwhVcGmPQnnAwabnosYQzRWxR0OygH5Kd8mePh6FheIRIigfXsDO8f/jdxwut8buvNIf3m5EBr3tUbTsvM+eV3M5vKGt7sk8T64DVtepTSdOOWtp+47ktsnHOMh immae@immae.eu"; | |
107 | }; | |
108 | ||
a05f8abe IB |
109 | services.ympd = mypkgs.ympd.config // { enable = true; }; |
110 | ||
58d1a782 | 111 | services.phpfpm = { |
66b5bbf6 IB |
112 | # /!\ phppackage is used in nextcloud configuation |
113 | phpOptions = '' | |
114 | ; For nextcloud | |
115 | extension=${pkgs.phpPackages.redis}/lib/php/extensions/redis.so | |
116 | ; For nextcloud | |
117 | extension=${pkgs.phpPackages.apcu}/lib/php/extensions/apcu.so | |
118 | ''; | |
58d1a782 IB |
119 | extraConfig = '' |
120 | log_level = notice | |
121 | ''; | |
122 | poolConfigs = { | |
27e22b76 | 123 | adminer = mypkgs.adminer.phpFpm.pool; |
65fe7543 | 124 | connexionswing_dev = mypkgs.connexionswing_dev.phpFpm.pool; |
e273ef92 | 125 | connexionswing_prod = mypkgs.connexionswing_prod.phpFpm.pool; |
66b5bbf6 | 126 | nextcloud = mypkgs.nextcloud.phpFpm.pool; |
58d1a782 IB |
127 | }; |
128 | }; | |
129 | ||
65fe7543 IB |
130 | system.activationScripts = { |
131 | connexionswing_dev = mypkgs.connexionswing_dev.activationScript; | |
e273ef92 | 132 | connexionswing_prod = mypkgs.connexionswing_prod.activationScript; |
66b5bbf6 | 133 | nextcloud = mypkgs.nextcloud.activationScript; |
5dd28b43 IB |
134 | httpd = '' |
135 | install -d -m 0755 /var/lib/acme/acme-challenge | |
5dd28b43 | 136 | ''; |
60f67ae3 IB |
137 | redis = '' |
138 | mkdir -p /run/redis | |
139 | chown redis /run/redis | |
140 | ''; | |
5566d26d IB |
141 | gitolite = |
142 | assert mylibs.checkEnv "NIXOPS_GITOLITE_LDAP_PASSWORD"; | |
143 | let | |
144 | gitolite_ldap_groups = mylibs.wrap { | |
145 | name = "gitolite_ldap_groups.sh"; | |
146 | file = ./packages/gitolite_ldap_groups.sh; | |
147 | vars = { | |
148 | LDAP_PASS = builtins.getEnv "NIXOPS_GITOLITE_LDAP_PASSWORD"; | |
149 | }; | |
150 | paths = [ pkgs.openldap pkgs.stdenv.shellPackage pkgs.gnugrep pkgs.coreutils ]; | |
151 | }; | |
152 | in { | |
153 | deps = [ "users" ]; | |
154 | text = '' | |
155 | if [ -d /var/lib/gitolite ]; then | |
156 | ln -sf ${gitolite_ldap_groups} /var/lib/gitolite/gitolite_ldap_groups.sh | |
157 | fi | |
158 | ''; | |
159 | }; | |
160 | }; | |
161 | ||
162 | environment.etc."ssh/ldap_authorized_keys" = let | |
163 | ldap_authorized_keys = | |
164 | assert mylibs.checkEnv "NIXOPS_SSHD_LDAP_PASSWORD"; | |
165 | mylibs.wrap { | |
166 | name = "ldap_authorized_keys"; | |
167 | file = ./ldap_authorized_keys.sh; | |
168 | vars = { | |
169 | LDAP_PASS = builtins.getEnv "NIXOPS_SSHD_LDAP_PASSWORD"; | |
170 | GITOLITE_SHELL = "${pkgs.gitolite}/bin/gitolite-shell"; | |
171 | ECHO = "${pkgs.coreutils}/bin/echo"; | |
172 | }; | |
173 | paths = [ pkgs.openldap pkgs.stdenv.shellPackage pkgs.gnugrep pkgs.gnused pkgs.coreutils ]; | |
174 | }; | |
175 | in { | |
176 | enable = true; | |
177 | mode = "0755"; | |
178 | user = "root"; | |
179 | source = ldap_authorized_keys; | |
65fe7543 IB |
180 | }; |
181 | ||
58d1a782 IB |
182 | services.httpd = let |
183 | withSSL = domain: { | |
184 | enableSSL = true; | |
5dd28b43 | 185 | sslServerCert = "/var/lib/acme/${domain}/cert.pem"; |
58d1a782 IB |
186 | sslServerKey = "/var/lib/acme/${domain}/key.pem"; |
187 | sslServerChain = "/var/lib/acme/${domain}/fullchain.pem"; | |
188 | }; | |
94818b75 IB |
189 | apacheConfig = { |
190 | gzip = { | |
191 | modules = [ "deflate" "filter" ]; | |
192 | extraConfig = '' | |
193 | AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript | |
194 | ''; | |
195 | }; | |
196 | ldap = { | |
197 | modules = [ "ldap" "authnz_ldap" ]; | |
198 | extraConfig = assert mylibs.checkEnv "NIXOPS_HTTP_LDAP_PASSWORD"; '' | |
199 | <IfModule ldap_module> | |
200 | LDAPSharedCacheSize 500000 | |
201 | LDAPCacheEntries 1024 | |
202 | LDAPCacheTTL 600 | |
203 | LDAPOpCacheEntries 1024 | |
204 | LDAPOpCacheTTL 600 | |
205 | </IfModule> | |
206 | ||
207 | <Macro LDAPConnect> | |
208 | <IfModule authnz_ldap_module> | |
209 | AuthLDAPURL ldap://ldap.immae.eu:389/dc=immae,dc=eu | |
210 | AuthLDAPBindDN cn=httpd,ou=services,dc=immae,dc=eu | |
211 | AuthLDAPBindPassword "${builtins.getEnv "NIXOPS_HTTP_LDAP_PASSWORD"}" | |
212 | AuthType Basic | |
213 | AuthName "Authentification requise (Acces LDAP)" | |
214 | AuthBasicProvider ldap | |
215 | </IfModule> | |
216 | </Macro> | |
217 | ''; | |
218 | }; | |
219 | }; | |
58d1a782 | 220 | in rec { |
a1bb33c4 | 221 | enable = true; |
58d1a782 IB |
222 | logPerVirtualHost = true; |
223 | multiProcessingModule = "worker"; | |
224 | adminAddr = "httpd@immae.eu"; | |
25fd1d16 | 225 | # FIXME: http2 |
94818b75 IB |
226 | # FIXME: voir les autres modules: |
227 | # authz_core_module | |
228 | # reqtimeout_module | |
229 | # http2_module | |
230 | # version_module | |
231 | # proxy_connect_module | |
232 | # proxy_ftp_module | |
233 | # proxy_scgi_module | |
234 | # proxy_ajp_module | |
235 | # proxy_balancer_module | |
236 | # proxy_express_module | |
237 | # lbmethod_byrequests_module | |
238 | # lbmethod_bytraffic_module | |
239 | # lbmethod_bybusyness_module | |
240 | # lbmethod_heartbeat_module | |
241 | ||
25fd1d16 IB |
242 | extraModules = pkgs.lib.lists.unique ( |
243 | mypkgs.adminer.apache.modules ++ | |
66b5bbf6 | 244 | mypkgs.nextcloud.apache.modules ++ |
65fe7543 | 245 | mypkgs.connexionswing_dev.apache.modules ++ |
e273ef92 | 246 | mypkgs.connexionswing_prod.apache.modules ++ |
5f3e023d | 247 | mypkgs.ympd.apache.modules ++ |
94818b75 IB |
248 | pkgs.lib.lists.flatten (pkgs.lib.attrsets.mapAttrsToList (n: v: v.modules) apacheConfig) ++ |
249 | [ "macro" ]); | |
250 | extraConfig = builtins.concatStringsSep "\n" | |
251 | (pkgs.lib.attrsets.mapAttrsToList (n: v: v.extraConfig) apacheConfig); | |
58d1a782 IB |
252 | virtualHosts = [ |
253 | (withSSL "eldiron" // { | |
254 | listen = [ { ip = "*"; port = 443; } ]; | |
255 | hostName = "eldiron.immae.eu"; | |
1d4ccb2c IB |
256 | documentRoot = ./www; |
257 | extraConfig = '' | |
258 | DirectoryIndex index.htm | |
259 | ''; | |
58d1a782 IB |
260 | }) |
261 | (withSSL "eldiron" // { | |
262 | listen = [ { ip = "*"; port = 443; } ]; | |
263 | hostName = "db-1.immae.eu"; | |
264 | documentRoot = null; | |
27e22b76 | 265 | extraConfig = builtins.concatStringsSep "\n" [ |
1bb2ff2c | 266 | mypkgs.adminer.apache.vhostConf |
27e22b76 | 267 | ]; |
58d1a782 | 268 | }) |
e379fd29 IB |
269 | (withSSL "eldiron" // { |
270 | listen = [ { ip = "*"; port = 443; } ]; | |
271 | hostName = "tools.immae.eu"; | |
272 | documentRoot = null; | |
273 | extraConfig = builtins.concatStringsSep "\n" [ | |
1bb2ff2c | 274 | mypkgs.adminer.apache.vhostConf |
a05f8abe | 275 | mypkgs.ympd.apache.vhostConf |
e379fd29 IB |
276 | ]; |
277 | }) | |
65fe7543 IB |
278 | (withSSL "eldiron" // { |
279 | listen = [ { ip = "*"; port = 443; } ]; | |
280 | hostName = "connexionswing.immae.eu"; | |
281 | serverAliases = [ "sandetludo.immae.eu" ]; | |
282 | documentRoot = mypkgs.connexionswing_dev.webRoot; | |
283 | extraConfig = builtins.concatStringsSep "\n" [ | |
284 | mypkgs.connexionswing_dev.apache.vhostConf | |
285 | ]; | |
286 | }) | |
66b5bbf6 IB |
287 | (withSSL "eldiron" // { |
288 | listen = [ { ip = "*"; port = 443; } ]; | |
289 | hostName = "cloud.immae.eu"; | |
290 | documentRoot = mypkgs.nextcloud.webRoot; | |
291 | extraConfig = builtins.concatStringsSep "\n" [ | |
292 | mypkgs.nextcloud.apache.vhostConf | |
293 | ]; | |
294 | }) | |
58d1a782 IB |
295 | { # Should go last, default fallback |
296 | listen = [ { ip = "*"; port = 80; } ]; | |
297 | hostName = "redirectSSL"; | |
298 | serverAliases = [ "*" ]; | |
299 | enableSSL = false; | |
58d1a782 IB |
300 | documentRoot = "/var/lib/acme/acme-challenge"; |
301 | extraConfig = '' | |
302 | RewriteEngine on | |
303 | RewriteCond "%{REQUEST_URI}" "!^/\.well-known" | |
304 | RewriteRule ^(.+) https://%{HTTP_HOST}$1 [R=301] | |
305 | # To redirect in specific "VirtualHost *:80", do | |
306 | # RedirectMatch 301 ^/((?!\.well-known.*$).*)$ https://host/$1 | |
307 | # rather than rewrite | |
308 | ''; | |
309 | } | |
310 | ]; | |
311 | }; | |
312 | ||
dedf591d IB |
313 | security.pam.services = let |
314 | pam_ldap = pkgs.pam_ldap; | |
6cd8d6ce IB |
315 | pam_ldap_mysql = assert mylibs.checkEnv "NIXOPS_MYSQL_PAM_PASSWORD"; |
316 | pkgs.writeText "mysql.conf" '' | |
dedf591d IB |
317 | host ldap.immae.eu |
318 | base dc=immae,dc=eu | |
319 | binddn cn=mysql,cn=pam,ou=services,dc=immae,dc=eu | |
320 | bindpw ${builtins.getEnv "NIXOPS_MYSQL_PAM_PASSWORD"} | |
321 | pam_filter memberOf=cn=users,cn=mysql,cn=pam,ou=services,dc=immae,dc=eu | |
322 | ''; | |
323 | in [ | |
324 | { | |
325 | name = "mysql"; | |
326 | text = '' | |
327 | # https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/ | |
328 | auth required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql} | |
329 | account required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql} | |
330 | ''; | |
331 | } | |
332 | ]; | |
333 | ||
60f67ae3 IB |
334 | # FIXME: backup |
335 | services.redis = rec { | |
336 | enable = true; | |
337 | bind = "127.0.0.1"; | |
338 | unixSocket = "/run/redis/redis.sock"; | |
339 | extraConfig = '' | |
340 | unixsocketperm 777 | |
341 | maxclients 1024 | |
342 | ''; | |
343 | }; | |
344 | ||
dedf591d IB |
345 | # FIXME: initial sync |
346 | # FIXME: backup | |
347 | # FIXME: restart after pam | |
348 | # FIXME: pam access doesn’t work (because of php module) | |
27e22b76 | 349 | # FIXME: ssl |
dedf591d IB |
350 | services.mysql = rec { |
351 | enable = true; | |
352 | package = pkgs.mariadb.overrideAttrs(old: rec { | |
353 | cmakeFlags = old.cmakeFlags ++ [ "-DWITH_AUTHENTICATION_PAM=ON" ]; | |
354 | buildInputs = old.buildInputs ++ [ pkgs.pam ]; | |
355 | }); | |
356 | }; | |
357 | ||
a1bb33c4 | 358 | # FIXME: initial sync |
dedf591d | 359 | # FIXME: backup |
27e22b76 | 360 | # FIXME: ssl |
a1bb33c4 IB |
361 | services.postgresql = rec { |
362 | enable = true; | |
363 | package = pkgs.postgresql100.overrideAttrs(old: rec { | |
364 | passthru = old.passthru // { psqlSchema = "11.0"; }; | |
365 | name = "postgresql-11.1"; | |
366 | src = pkgs.fetchurl { | |
367 | url = "mirror://postgresql/source/v11.1/${name}.tar.bz2"; | |
368 | sha256 = "026v0sicsh7avzi45waf8shcbhivyxmi7qgn9fd1x0vl520mx0ch"; | |
369 | }; | |
370 | }); | |
371 | enableTCPIP = true; | |
372 | extraConfig = '' | |
373 | max_connections = 100 | |
374 | wal_level = logical | |
375 | shared_buffers = 128MB | |
376 | max_wal_size = 1GB | |
377 | min_wal_size = 80MB | |
378 | log_timezone = 'Europe/Paris' | |
379 | datestyle = 'iso, mdy' | |
380 | timezone = 'Europe/Paris' | |
381 | lc_messages = 'en_US.UTF-8' | |
382 | lc_monetary = 'en_US.UTF-8' | |
383 | lc_numeric = 'en_US.UTF-8' | |
384 | lc_time = 'en_US.UTF-8' | |
385 | default_text_search_config = 'pg_catalog.english' | |
386 | # ssl = on | |
387 | # ssl_cert_file = '/var/lib/acme/eldiron/fullchain.pem' | |
388 | # ssl_key_file = '/var/lib/acme/eldiron/key.pem' | |
389 | ''; | |
390 | authentication = '' | |
391 | local all postgres ident | |
392 | local all all md5 | |
393 | host all all 178.33.252.96/32 md5 | |
394 | host all all 188.165.209.148/32 md5 | |
395 | #host all all all pam | |
396 | ''; | |
397 | }; | |
398 | }; | |
399 | } |