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