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