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