]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - virtual/eldiron.nix
Add Connexionswing
[perso/Immae/Config/Nix.git] / virtual / eldiron.nix
1 {
2 network = {
3 description = "Immae's network";
4 enableRollback = true;
5 };
6
7 eldiron = { config, pkgs, ... }:
8 let mypkgs = import ./packages.nix;
9 mylibs = import ../libs.nix;
10 in
11 {
12 networking = {
13 firewall = {
14 enable = true;
15 allowedTCPPorts = [ 22 80 443 3306 5432 ];
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
39 # FIXME: how to run it? currently set as timer
40 security.acme.certs = {
41 "eldiron" = {
42 webroot = "/var/lib/acme/acme-challenge";
43 email = "ismael@bouya.org";
44 domain = "eldiron.immae.eu";
45 plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ];
46 postRun = ''
47 "systemctl reload httpd.service"
48 '';
49 extraDomains = {
50 "db-1.immae.eu" = null;
51 "tools.immae.eu" = null;
52 "connexionswing.immae.eu" = null;
53 "sandetludo.immae.eu" = null;
54 };
55 };
56 };
57
58 services.ympd = mypkgs.ympd.config // { enable = true; };
59
60 # FIXME: open_basedir
61 services.phpfpm = {
62 extraConfig = ''
63 log_level = notice
64 '';
65 poolConfigs = {
66 adminer = mypkgs.adminer.phpFpm.pool;
67 connexionswing_dev = mypkgs.connexionswing_dev.phpFpm.pool;
68 www = ''
69 listen = /var/run/phpfpm/www.sock
70 user = wwwrun
71 group = wwwrun
72 listen.owner = wwwrun
73 listen.group = wwwrun
74 pm = ondemand
75 pm.max_children = 5
76 pm.process_idle_timeout = 60
77 ;php_admin_flag[log_errors] = on
78 php_admin_value[open_basedir] = "/var/www"
79 '';
80 };
81 };
82
83 system.activationScripts = {
84 connexionswing_dev = mypkgs.connexionswing_dev.activationScript;
85 };
86
87 services.httpd = let
88 withSSL = domain: {
89 enableSSL = true;
90 sslServerCert = "/var/lib/acme/${domain}/full.pem"; # FIXME: cert only?
91 sslServerKey = "/var/lib/acme/${domain}/key.pem";
92 sslServerChain = "/var/lib/acme/${domain}/fullchain.pem";
93 };
94 in rec {
95 enable = true;
96 logPerVirtualHost = true;
97 multiProcessingModule = "worker";
98 adminAddr = "httpd@immae.eu";
99 # FIXME: http2
100 extraModules = pkgs.lib.lists.unique (
101 mypkgs.adminer.apache.modules ++
102 mypkgs.connexionswing_dev.apache.modules ++
103 [
104 "macro"
105 "ldap"
106 "authnz_ldap"
107 ]);
108 extraConfig = assert mylibs.checkEnv "NIXOPS_HTTP_LDAP_PASSWORD"; ''
109 <IfModule ldap_module>
110 LDAPSharedCacheSize 500000
111 LDAPCacheEntries 1024
112 LDAPCacheTTL 600
113 LDAPOpCacheEntries 1024
114 LDAPOpCacheTTL 600
115 </IfModule>
116
117 <Macro LDAPConnect>
118 <IfModule authnz_ldap_module>
119 AuthLDAPURL ldap://ldap.immae.eu:389/dc=immae,dc=eu
120 AuthLDAPBindDN cn=httpd,ou=services,dc=immae,dc=eu
121 AuthLDAPBindPassword "${builtins.getEnv "NIXOPS_HTTP_LDAP_PASSWORD"}"
122 AuthType Basic
123 AuthName "Authentification requise (Acces LDAP)"
124 AuthBasicProvider ldap
125 </IfModule>
126 </Macro>
127 '';
128 virtualHosts = [
129 (withSSL "eldiron" // {
130 listen = [ { ip = "*"; port = 443; } ];
131 hostName = "eldiron.immae.eu";
132 # FIXME: directory needs to exist
133 documentRoot = "/var/www";
134 })
135 (withSSL "eldiron" // {
136 listen = [ { ip = "*"; port = 443; } ];
137 hostName = "db-1.immae.eu";
138 documentRoot = null;
139 extraConfig = builtins.concatStringsSep "\n" [
140 mypkgs.adminer.apache.vhostConf
141 ];
142 })
143 (withSSL "eldiron" // {
144 listen = [ { ip = "*"; port = 443; } ];
145 hostName = "tools.immae.eu";
146 documentRoot = null;
147 extraConfig = builtins.concatStringsSep "\n" [
148 mypkgs.adminer.apache.vhostConf
149 mypkgs.ympd.apache.vhostConf
150 ];
151 })
152 (withSSL "eldiron" // {
153 listen = [ { ip = "*"; port = 443; } ];
154 hostName = "connexionswing.immae.eu";
155 serverAliases = [ "sandetludo.immae.eu" ];
156 documentRoot = mypkgs.connexionswing_dev.webRoot;
157 extraConfig = builtins.concatStringsSep "\n" [
158 mypkgs.connexionswing_dev.apache.vhostConf
159 ];
160 })
161 { # Should go last, default fallback
162 listen = [ { ip = "*"; port = 80; } ];
163 hostName = "redirectSSL";
164 serverAliases = [ "*" ];
165 enableSSL = false;
166 # FIXME: directory needs to exist
167 documentRoot = "/var/lib/acme/acme-challenge";
168 extraConfig = ''
169 RewriteEngine on
170 RewriteCond "%{REQUEST_URI}" "!^/\.well-known"
171 RewriteRule ^(.+) https://%{HTTP_HOST}$1 [R=301]
172 # To redirect in specific "VirtualHost *:80", do
173 # RedirectMatch 301 ^/((?!\.well-known.*$).*)$ https://host/$1
174 # rather than rewrite
175 '';
176 }
177 ];
178 };
179
180 # FIXME: environment variables ?
181 security.pam.services = let
182 pam_ldap = pkgs.pam_ldap;
183 pam_ldap_mysql = assert mylibs.checkEnv "NIXOPS_MYSQL_PAM_PASSWORD";
184 pkgs.writeText "mysql.conf" ''
185 host ldap.immae.eu
186 base dc=immae,dc=eu
187 binddn cn=mysql,cn=pam,ou=services,dc=immae,dc=eu
188 bindpw ${builtins.getEnv "NIXOPS_MYSQL_PAM_PASSWORD"}
189 pam_filter memberOf=cn=users,cn=mysql,cn=pam,ou=services,dc=immae,dc=eu
190 '';
191 in [
192 {
193 name = "mysql";
194 text = ''
195 # https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/
196 auth required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql}
197 account required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql}
198 '';
199 }
200 ];
201
202 # FIXME: initial sync
203 # FIXME: backup
204 # FIXME: restart after pam
205 # FIXME: pam access doesn’t work (because of php module)
206 # FIXME: ssl
207 services.mysql = rec {
208 enable = true;
209 package = pkgs.mariadb.overrideAttrs(old: rec {
210 cmakeFlags = old.cmakeFlags ++ [ "-DWITH_AUTHENTICATION_PAM=ON" ];
211 buildInputs = old.buildInputs ++ [ pkgs.pam ];
212 });
213 };
214
215 # FIXME: initial sync
216 # FIXME: backup
217 # FIXME: ssl
218 services.postgresql = rec {
219 enable = true;
220 package = pkgs.postgresql100.overrideAttrs(old: rec {
221 passthru = old.passthru // { psqlSchema = "11.0"; };
222 name = "postgresql-11.1";
223 src = pkgs.fetchurl {
224 url = "mirror://postgresql/source/v11.1/${name}.tar.bz2";
225 sha256 = "026v0sicsh7avzi45waf8shcbhivyxmi7qgn9fd1x0vl520mx0ch";
226 };
227 });
228 enableTCPIP = true;
229 extraConfig = ''
230 max_connections = 100
231 wal_level = logical
232 shared_buffers = 128MB
233 max_wal_size = 1GB
234 min_wal_size = 80MB
235 log_timezone = 'Europe/Paris'
236 datestyle = 'iso, mdy'
237 timezone = 'Europe/Paris'
238 lc_messages = 'en_US.UTF-8'
239 lc_monetary = 'en_US.UTF-8'
240 lc_numeric = 'en_US.UTF-8'
241 lc_time = 'en_US.UTF-8'
242 default_text_search_config = 'pg_catalog.english'
243 # ssl = on
244 # ssl_cert_file = '/var/lib/acme/eldiron/fullchain.pem'
245 # ssl_key_file = '/var/lib/acme/eldiron/key.pem'
246 '';
247 authentication = ''
248 local all postgres ident
249 local all all md5
250 host all all 178.33.252.96/32 md5
251 host all all 188.165.209.148/32 md5
252 #host all all all pam
253 '';
254 };
255 };
256 }