]>
Commit | Line | Data |
---|---|---|
1 | { | |
2 | network = { | |
3 | description = "Immae's network"; | |
4 | enableRollback = true; | |
5 | }; | |
6 | ||
7 | eldiron = { config, pkgs, ... }: | |
8 | with import ../libs.nix; | |
9 | let | |
10 | mypkgs = pkgs.callPackage ./packages.nix { | |
11 | inherit checkEnv fetchedGitPrivate fetchedGithub; | |
12 | }; | |
13 | in | |
14 | { | |
15 | # FIXME: they are not overriden in packages.nix | |
16 | # (see nix-store -q --tree /nix/var/nix/profiles/system) | |
17 | nixpkgs.config.packageOverrides = oldpkgs: rec { | |
18 | gitolite = nixpkgs_unstable.gitolite; | |
19 | gitweb = oldpkgs.gitweb.overrideAttrs(old: { | |
20 | installPhase = old.installPhase + '' | |
21 | cp -r ${./packages/gitweb} $out/gitweb-theme; | |
22 | ''; | |
23 | }); | |
24 | postgresql = postgresql111; | |
25 | postgresql111 = oldpkgs.postgresql100.overrideAttrs(old: rec { | |
26 | passthru = old.passthru // { psqlSchema = "11.0"; }; | |
27 | name = "postgresql-11.1"; | |
28 | src = pkgs.fetchurl { | |
29 | url = "mirror://postgresql/source/v11.1/${name}.tar.bz2"; | |
30 | sha256 = "026v0sicsh7avzi45waf8shcbhivyxmi7qgn9fd1x0vl520mx0ch"; | |
31 | }; | |
32 | }); | |
33 | mariadb = mariadbPAM; | |
34 | mariadbPAM = oldpkgs.mariadb.overrideAttrs(old: rec { | |
35 | cmakeFlags = old.cmakeFlags ++ [ "-DWITH_AUTHENTICATION_PAM=ON" ]; | |
36 | buildInputs = old.buildInputs ++ [ pkgs.pam ]; | |
37 | }); | |
38 | }; | |
39 | ||
40 | networking = { | |
41 | firewall = { | |
42 | enable = true; | |
43 | allowedTCPPorts = [ 22 80 443 3306 5432 9418 ]; | |
44 | }; | |
45 | }; | |
46 | ||
47 | deployment = { | |
48 | targetEnv = "hetzner"; | |
49 | hetzner = { | |
50 | #robotUser = "defined in HETZNER_ROBOT_USER"; | |
51 | #robotPass = "defined in HETZNER_ROBOT_PASS"; | |
52 | mainIPv4 = "176.9.151.89"; | |
53 | partitions = '' | |
54 | clearpart --all --initlabel --drives=sda,sdb | |
55 | ||
56 | part swap1 --recommended --label=swap1 --fstype=swap --ondisk=sda | |
57 | part swap2 --recommended --label=swap2 --fstype=swap --ondisk=sdb | |
58 | ||
59 | part raid.1 --grow --ondisk=sda | |
60 | part raid.2 --grow --ondisk=sdb | |
61 | ||
62 | raid / --level=1 --device=md0 --fstype=ext4 --label=root raid.1 raid.2 | |
63 | ''; | |
64 | }; | |
65 | }; | |
66 | ||
67 | environment.systemPackages = let | |
68 | # FIXME: move it to nextcloud | |
69 | occ = pkgs.writeScriptBin "nextcloud-occ" '' | |
70 | #! ${pkgs.stdenv.shell} | |
71 | cd ${mypkgs.nextcloud.webRoot} | |
72 | NEXTCLOUD_CONFIG_DIR="${mypkgs.nextcloud.webRoot}/config" \ | |
73 | exec \ | |
74 | ${config.services.phpfpm.phpPackage}/bin/php \ | |
75 | -c ${config.services.phpfpm.phpPackage}/etc/php.ini \ | |
76 | occ $* | |
77 | ''; | |
78 | in [ | |
79 | pkgs.telnet | |
80 | pkgs.vim | |
81 | occ | |
82 | ]; | |
83 | ||
84 | security.acme.certs = { | |
85 | "eldiron" = { | |
86 | webroot = "/var/lib/acme/acme-challenge"; | |
87 | email = "ismael@bouya.org"; | |
88 | domain = "eldiron.immae.eu"; | |
89 | plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ]; | |
90 | postRun = '' | |
91 | systemctl reload httpd.service | |
92 | ''; | |
93 | extraDomains = { | |
94 | "db-1.immae.eu" = null; | |
95 | "git.immae.eu" = null; | |
96 | "tools.immae.eu" = null; | |
97 | "connexionswing.immae.eu" = null; | |
98 | "sandetludo.immae.eu" = null; | |
99 | "cloud.immae.eu" = null; | |
100 | }; | |
101 | }; | |
102 | # "connexionswing" = { | |
103 | # webroot = "/var/lib/acme/acme-challenge"; | |
104 | # email = "ismael@bouya.org"; | |
105 | # domain = "connexionswing.com"; | |
106 | # plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ]; | |
107 | # postRun = '' | |
108 | # systemctl reload httpd.service | |
109 | # ''; | |
110 | # extraDomains = { | |
111 | # "www.connexionswing.com" = null; | |
112 | # "sandetludo.com" = null; | |
113 | # "www.sandetludo.com" = null; | |
114 | # }; | |
115 | # }; | |
116 | }; | |
117 | ||
118 | services.openssh.extraConfig = '' | |
119 | AuthorizedKeysCommand /etc/ssh/ldap_authorized_keys | |
120 | AuthorizedKeysCommandUser nobody | |
121 | ''; | |
122 | ||
123 | users.users.wwwrun.extraGroups = [ "gitolite" ]; | |
124 | ||
125 | users.users.gitolite.packages = let | |
126 | python-packages = python-packages: with python-packages; [ | |
127 | simplejson | |
128 | urllib3 | |
129 | ]; | |
130 | in | |
131 | [ | |
132 | (pkgs.python3.withPackages python-packages) | |
133 | ]; | |
134 | # FIXME: after initial install, need to | |
135 | # (1) copy rc file (adjust gitolite_ldap_groups.sh) | |
136 | # (2) (mark old readonly and) sync repos except gitolite-admin | |
137 | # rsync -av --exclude=gitolite-admin.git old:/var/lib/gitolite/repositories /var/lib/gitolite/ | |
138 | # chown -R gitolite:gitolite /var/lib/gitolite | |
139 | # (3) push force the gitolite-admin to new location (from external point) | |
140 | # Don't use an existing key, it will take precedence over | |
141 | # gitolite-admin | |
142 | # (4) su -u gitolite gitolite setup | |
143 | services.gitolite = { | |
144 | enable = true; | |
145 | # FIXME: key from ./ssh | |
146 | adminPubkey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDXqRbiHw7QoHADNIEuo4nUT9fSOIEBMdJZH0bkQAxXyJFyCM1IMz0pxsHV0wu9tdkkr36bPEUj2aV5bkYLBN6nxcV2Y49X8bjOSCPfx3n6Own1h+NeZVBj4ZByrFmqCbTxUJIZ2bZKcWOFncML39VmWdsVhNjg0X4NBBehqXRIKr2gt3E/ESAxTYJFm0BnU0baciw9cN0bsRGqvFgf5h2P48CIAfwhVcGmPQnnAwabnosYQzRWxR0OygH5Kd8mePh6FheIRIigfXsDO8f/jdxwut8buvNIf3m5EBr3tUbTsvM+eV3M5vKGt7sk8T64DVtepTSdOOWtp+47ktsnHOMh immae@immae.eu"; | |
147 | }; | |
148 | ||
149 | services.ympd = mypkgs.ympd.config // { enable = true; }; | |
150 | ||
151 | services.phpfpm = { | |
152 | # /!\ phppackage is used in nextcloud configuation | |
153 | phpOptions = '' | |
154 | ; For nextcloud | |
155 | extension=${pkgs.phpPackages.redis}/lib/php/extensions/redis.so | |
156 | ; For nextcloud | |
157 | extension=${pkgs.phpPackages.apcu}/lib/php/extensions/apcu.so | |
158 | ; For nextcloud | |
159 | zend_extension=${pkgs.php}/lib/php/extensions/opcache.so | |
160 | ''; | |
161 | extraConfig = '' | |
162 | log_level = notice | |
163 | ''; | |
164 | poolConfigs = { | |
165 | adminer = mypkgs.adminer.phpFpm.pool; | |
166 | connexionswing_dev = mypkgs.connexionswing_dev.phpFpm.pool; | |
167 | connexionswing_prod = mypkgs.connexionswing_prod.phpFpm.pool; | |
168 | nextcloud = mypkgs.nextcloud.phpFpm.pool; | |
169 | mantisbt = mypkgs.mantisbt.phpFpm.pool; | |
170 | }; | |
171 | }; | |
172 | ||
173 | system.activationScripts = { | |
174 | connexionswing_dev = mypkgs.connexionswing_dev.activationScript; | |
175 | connexionswing_prod = mypkgs.connexionswing_prod.activationScript; | |
176 | nextcloud = mypkgs.nextcloud.activationScript; | |
177 | httpd = '' | |
178 | install -d -m 0755 /var/lib/acme/acme-challenge | |
179 | ''; | |
180 | redis = '' | |
181 | mkdir -p /run/redis | |
182 | chown redis /run/redis | |
183 | ''; | |
184 | gitolite = | |
185 | assert checkEnv "NIXOPS_GITOLITE_LDAP_PASSWORD"; | |
186 | let | |
187 | gitolite_ldap_groups = wrap { | |
188 | name = "gitolite_ldap_groups.sh"; | |
189 | file = ./packages/gitolite_ldap_groups.sh; | |
190 | vars = { | |
191 | LDAP_PASS = builtins.getEnv "NIXOPS_GITOLITE_LDAP_PASSWORD"; | |
192 | }; | |
193 | paths = [ pkgs.openldap pkgs.stdenv.shellPackage pkgs.gnugrep pkgs.coreutils ]; | |
194 | }; | |
195 | in { | |
196 | deps = [ "users" ]; | |
197 | text = '' | |
198 | if [ -d /var/lib/gitolite ]; then | |
199 | ln -sf ${gitolite_ldap_groups} /var/lib/gitolite/gitolite_ldap_groups.sh | |
200 | chmod g+rx /var/lib/gitolite | |
201 | fi | |
202 | if [ -f /var/lib/gitolite/projects.list ]; then | |
203 | chmod g+r /var/lib/gitolite/projects.list | |
204 | fi | |
205 | ''; | |
206 | }; | |
207 | }; | |
208 | ||
209 | environment.etc."ssh/ldap_authorized_keys" = let | |
210 | ldap_authorized_keys = | |
211 | assert checkEnv "NIXOPS_SSHD_LDAP_PASSWORD"; | |
212 | wrap { | |
213 | name = "ldap_authorized_keys"; | |
214 | file = ./ldap_authorized_keys.sh; | |
215 | vars = { | |
216 | LDAP_PASS = builtins.getEnv "NIXOPS_SSHD_LDAP_PASSWORD"; | |
217 | GITOLITE_SHELL = "${pkgs.gitolite}/bin/gitolite-shell"; | |
218 | ECHO = "${pkgs.coreutils}/bin/echo"; | |
219 | }; | |
220 | paths = [ pkgs.openldap pkgs.stdenv.shellPackage pkgs.gnugrep pkgs.gnused pkgs.coreutils ]; | |
221 | }; | |
222 | in { | |
223 | enable = true; | |
224 | mode = "0755"; | |
225 | user = "root"; | |
226 | source = ldap_authorized_keys; | |
227 | }; | |
228 | ||
229 | services.gitDaemon = { | |
230 | enable = true; | |
231 | user = "gitolite"; | |
232 | group = "gitolite"; | |
233 | basePath = "${mypkgs.git.web.varDir}/repositories"; | |
234 | }; | |
235 | ||
236 | services.httpd = let | |
237 | withSSL = domain: { | |
238 | enableSSL = true; | |
239 | sslServerCert = "/var/lib/acme/${domain}/cert.pem"; | |
240 | sslServerKey = "/var/lib/acme/${domain}/key.pem"; | |
241 | sslServerChain = "/var/lib/acme/${domain}/fullchain.pem"; | |
242 | }; | |
243 | apacheConfig = { | |
244 | gzip = { | |
245 | modules = [ "deflate" "filter" ]; | |
246 | extraConfig = '' | |
247 | AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript | |
248 | ''; | |
249 | }; | |
250 | ldap = { | |
251 | modules = [ "ldap" "authnz_ldap" ]; | |
252 | extraConfig = assert checkEnv "NIXOPS_HTTP_LDAP_PASSWORD"; '' | |
253 | <IfModule ldap_module> | |
254 | LDAPSharedCacheSize 500000 | |
255 | LDAPCacheEntries 1024 | |
256 | LDAPCacheTTL 600 | |
257 | LDAPOpCacheEntries 1024 | |
258 | LDAPOpCacheTTL 600 | |
259 | </IfModule> | |
260 | ||
261 | <Macro LDAPConnect> | |
262 | <IfModule authnz_ldap_module> | |
263 | AuthLDAPURL ldap://ldap.immae.eu:389/dc=immae,dc=eu | |
264 | AuthLDAPBindDN cn=httpd,ou=services,dc=immae,dc=eu | |
265 | AuthLDAPBindPassword "${builtins.getEnv "NIXOPS_HTTP_LDAP_PASSWORD"}" | |
266 | AuthType Basic | |
267 | AuthName "Authentification requise (Acces LDAP)" | |
268 | AuthBasicProvider ldap | |
269 | </IfModule> | |
270 | </Macro> | |
271 | ''; | |
272 | }; | |
273 | }; | |
274 | in rec { | |
275 | enable = true; | |
276 | logPerVirtualHost = true; | |
277 | multiProcessingModule = "worker"; | |
278 | adminAddr = "httpd@immae.eu"; | |
279 | # FIXME: http2 | |
280 | # FIXME: voir les autres modules: | |
281 | # authz_core_module | |
282 | # reqtimeout_module | |
283 | # http2_module | |
284 | # version_module | |
285 | # proxy_connect_module | |
286 | # proxy_ftp_module | |
287 | # proxy_scgi_module | |
288 | # proxy_ajp_module | |
289 | # proxy_balancer_module | |
290 | # proxy_express_module | |
291 | # lbmethod_byrequests_module | |
292 | # lbmethod_bytraffic_module | |
293 | # lbmethod_bybusyness_module | |
294 | # lbmethod_heartbeat_module | |
295 | ||
296 | extraModules = pkgs.lib.lists.unique ( | |
297 | mypkgs.adminer.apache.modules ++ | |
298 | mypkgs.nextcloud.apache.modules ++ | |
299 | mypkgs.connexionswing_dev.apache.modules ++ | |
300 | mypkgs.connexionswing_prod.apache.modules ++ | |
301 | mypkgs.ympd.apache.modules ++ | |
302 | mypkgs.git.web.apache.modules ++ | |
303 | mypkgs.mantisbt.apache.modules ++ | |
304 | pkgs.lib.lists.flatten (pkgs.lib.attrsets.mapAttrsToList (n: v: v.modules) apacheConfig) ++ | |
305 | [ "macro" ]); | |
306 | extraConfig = builtins.concatStringsSep "\n" | |
307 | (pkgs.lib.attrsets.mapAttrsToList (n: v: v.extraConfig) apacheConfig); | |
308 | virtualHosts = [ | |
309 | (withSSL "eldiron" // { | |
310 | listen = [ { ip = "*"; port = 443; } ]; | |
311 | hostName = "eldiron.immae.eu"; | |
312 | documentRoot = ./www; | |
313 | extraConfig = '' | |
314 | DirectoryIndex index.htm | |
315 | ''; | |
316 | }) | |
317 | (withSSL "eldiron" // { | |
318 | listen = [ { ip = "*"; port = 443; } ]; | |
319 | hostName = "db-1.immae.eu"; | |
320 | documentRoot = null; | |
321 | extraConfig = builtins.concatStringsSep "\n" [ | |
322 | mypkgs.adminer.apache.vhostConf | |
323 | ]; | |
324 | }) | |
325 | (withSSL "eldiron" // { | |
326 | listen = [ { ip = "*"; port = 443; } ]; | |
327 | hostName = "tools.immae.eu"; | |
328 | documentRoot = null; | |
329 | extraConfig = builtins.concatStringsSep "\n" [ | |
330 | mypkgs.adminer.apache.vhostConf | |
331 | mypkgs.ympd.apache.vhostConf | |
332 | ]; | |
333 | }) | |
334 | (withSSL "eldiron" // { | |
335 | listen = [ { ip = "*"; port = 443; } ]; | |
336 | hostName = "connexionswing.immae.eu"; | |
337 | serverAliases = [ "sandetludo.immae.eu" ]; | |
338 | documentRoot = mypkgs.connexionswing_dev.webRoot; | |
339 | extraConfig = builtins.concatStringsSep "\n" [ | |
340 | mypkgs.connexionswing_dev.apache.vhostConf | |
341 | ]; | |
342 | }) | |
343 | (withSSL "eldiron" // { | |
344 | listen = [ { ip = "*"; port = 443; } ]; | |
345 | hostName = "cloud.immae.eu"; | |
346 | documentRoot = mypkgs.nextcloud.webRoot; | |
347 | extraConfig = builtins.concatStringsSep "\n" [ | |
348 | mypkgs.nextcloud.apache.vhostConf | |
349 | ]; | |
350 | }) | |
351 | (withSSL "eldiron" // { | |
352 | listen = [ { ip = "*"; port = 443; } ]; | |
353 | hostName = "git.immae.eu"; | |
354 | documentRoot = mypkgs.git.web.webRoot; | |
355 | extraConfig = builtins.concatStringsSep "\n" [ | |
356 | mypkgs.git.web.apache.vhostConf | |
357 | mypkgs.mantisbt.apache.vhostConf | |
358 | ] + '' | |
359 | RewriteEngine on | |
360 | RewriteCond %{REQUEST_URI} ^/releases | |
361 | RewriteRule /releases(.*) https://release.immae.eu$1 [P,L] | |
362 | ''; | |
363 | }) | |
364 | { # Should go last, default fallback | |
365 | listen = [ { ip = "*"; port = 80; } ]; | |
366 | hostName = "redirectSSL"; | |
367 | serverAliases = [ "*" ]; | |
368 | enableSSL = false; | |
369 | documentRoot = "/var/lib/acme/acme-challenge"; | |
370 | extraConfig = '' | |
371 | RewriteEngine on | |
372 | RewriteCond "%{REQUEST_URI}" "!^/\.well-known" | |
373 | RewriteRule ^(.+) https://%{HTTP_HOST}$1 [R=301] | |
374 | # To redirect in specific "VirtualHost *:80", do | |
375 | # RedirectMatch 301 ^/((?!\.well-known.*$).*)$ https://host/$1 | |
376 | # rather than rewrite | |
377 | ''; | |
378 | } | |
379 | ]; | |
380 | }; | |
381 | ||
382 | security.pam.services = let | |
383 | pam_ldap = pkgs.pam_ldap; | |
384 | pam_ldap_mysql = assert checkEnv "NIXOPS_MYSQL_PAM_PASSWORD"; | |
385 | pkgs.writeText "mysql.conf" '' | |
386 | host ldap.immae.eu | |
387 | base dc=immae,dc=eu | |
388 | binddn cn=mysql,cn=pam,ou=services,dc=immae,dc=eu | |
389 | bindpw ${builtins.getEnv "NIXOPS_MYSQL_PAM_PASSWORD"} | |
390 | pam_filter memberOf=cn=users,cn=mysql,cn=pam,ou=services,dc=immae,dc=eu | |
391 | ''; | |
392 | in [ | |
393 | { | |
394 | name = "mysql"; | |
395 | text = '' | |
396 | # https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/ | |
397 | auth required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql} | |
398 | account required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql} | |
399 | ''; | |
400 | } | |
401 | ]; | |
402 | ||
403 | # FIXME: backup | |
404 | services.redis = rec { | |
405 | enable = true; | |
406 | bind = "127.0.0.1"; | |
407 | unixSocket = "/run/redis/redis.sock"; | |
408 | extraConfig = '' | |
409 | unixsocketperm 777 | |
410 | maxclients 1024 | |
411 | ''; | |
412 | }; | |
413 | ||
414 | # FIXME: initial sync | |
415 | # FIXME: backup | |
416 | # FIXME: restart after pam | |
417 | # FIXME: pam access doesn’t work (because of php module) | |
418 | # FIXME: ssl | |
419 | services.mysql = rec { | |
420 | enable = true; | |
421 | package = pkgs.mariadb; | |
422 | }; | |
423 | ||
424 | # FIXME: initial sync | |
425 | # FIXME: backup | |
426 | # FIXME: ssl | |
427 | services.postgresql = rec { | |
428 | enable = true; | |
429 | package = pkgs.postgresql; | |
430 | enableTCPIP = true; | |
431 | extraConfig = '' | |
432 | max_connections = 100 | |
433 | wal_level = logical | |
434 | shared_buffers = 128MB | |
435 | max_wal_size = 1GB | |
436 | min_wal_size = 80MB | |
437 | log_timezone = 'Europe/Paris' | |
438 | datestyle = 'iso, mdy' | |
439 | timezone = 'Europe/Paris' | |
440 | lc_messages = 'en_US.UTF-8' | |
441 | lc_monetary = 'en_US.UTF-8' | |
442 | lc_numeric = 'en_US.UTF-8' | |
443 | lc_time = 'en_US.UTF-8' | |
444 | default_text_search_config = 'pg_catalog.english' | |
445 | # ssl = on | |
446 | # ssl_cert_file = '/var/lib/acme/eldiron/fullchain.pem' | |
447 | # ssl_key_file = '/var/lib/acme/eldiron/key.pem' | |
448 | ''; | |
449 | authentication = '' | |
450 | local all postgres ident | |
451 | local all all md5 | |
452 | host all all samehost md5 | |
453 | host all all 178.33.252.96/32 md5 | |
454 | host all all 188.165.209.148/32 md5 | |
455 | #host all all all pam | |
456 | ''; | |
457 | }; | |
458 | }; | |
459 | } |