3 description = "Immae's network";
7 eldiron = { config, pkgs, ... }:
8 let mypkgs = import ./packages.nix;
9 mylibs = import ../libs.nix;
15 allowedTCPPorts = [ 22 80 443 3306 5432 ];
20 targetEnv = "hetzner";
22 #robotUser = "defined in HETZNER_ROBOT_USER";
23 #robotPass = "defined in HETZNER_ROBOT_PASS";
24 mainIPv4 = "176.9.151.89";
26 clearpart --all --initlabel --drives=sda,sdb
28 part swap1 --recommended --label=swap1 --fstype=swap --ondisk=sda
29 part swap2 --recommended --label=swap2 --fstype=swap --ondisk=sdb
31 part raid.1 --grow --ondisk=sda
32 part raid.2 --grow --ondisk=sdb
34 raid / --level=1 --device=md0 --fstype=ext4 --label=root raid.1 raid.2
39 environment.systemPackages = [
44 security.acme.certs = {
46 webroot = "/var/lib/acme/acme-challenge";
47 email = "ismael@bouya.org";
48 domain = "eldiron.immae.eu";
49 plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ];
51 systemctl reload httpd.service
54 "db-1.immae.eu" = null;
55 "tools.immae.eu" = null;
56 "connexionswing.immae.eu" = null;
57 "sandetludo.immae.eu" = null;
60 # "connexionswing" = {
61 # webroot = "/var/lib/acme/acme-challenge";
62 # email = "ismael@bouya.org";
63 # domain = "connexionswing.com";
64 # plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ];
66 # systemctl reload httpd.service
69 # "www.connexionswing.com" = null;
70 # "sandetludo.com" = null;
71 # "www.sandetludo.com" = null;
76 services.ympd = mypkgs.ympd.config // { enable = true; };
83 adminer = mypkgs.adminer.phpFpm.pool;
84 connexionswing_dev = mypkgs.connexionswing_dev.phpFpm.pool;
85 connexionswing_prod = mypkgs.connexionswing_prod.phpFpm.pool;
89 system.activationScripts = {
90 connexionswing_dev = mypkgs.connexionswing_dev.activationScript;
91 connexionswing_prod = mypkgs.connexionswing_prod.activationScript;
93 install -d -m 0755 /var/lib/acme/acme-challenge
97 chown redis /run/redis
104 sslServerCert = "/var/lib/acme/${domain}/cert.pem";
105 sslServerKey = "/var/lib/acme/${domain}/key.pem";
106 sslServerChain = "/var/lib/acme/${domain}/fullchain.pem";
110 modules = [ "deflate" "filter" ];
112 AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
116 modules = [ "ldap" "authnz_ldap" ];
117 extraConfig = assert mylibs.checkEnv "NIXOPS_HTTP_LDAP_PASSWORD"; ''
118 <IfModule ldap_module>
119 LDAPSharedCacheSize 500000
120 LDAPCacheEntries 1024
122 LDAPOpCacheEntries 1024
127 <IfModule authnz_ldap_module>
128 AuthLDAPURL ldap://ldap.immae.eu:389/dc=immae,dc=eu
129 AuthLDAPBindDN cn=httpd,ou=services,dc=immae,dc=eu
130 AuthLDAPBindPassword "${builtins.getEnv "NIXOPS_HTTP_LDAP_PASSWORD"}"
132 AuthName "Authentification requise (Acces LDAP)"
133 AuthBasicProvider ldap
141 logPerVirtualHost = true;
142 multiProcessingModule = "worker";
143 adminAddr = "httpd@immae.eu";
145 # FIXME: voir les autres modules:
150 # proxy_connect_module
154 # proxy_balancer_module
155 # proxy_express_module
156 # lbmethod_byrequests_module
157 # lbmethod_bytraffic_module
158 # lbmethod_bybusyness_module
159 # lbmethod_heartbeat_module
161 extraModules = pkgs.lib.lists.unique (
162 mypkgs.adminer.apache.modules ++
163 mypkgs.connexionswing_dev.apache.modules ++
164 mypkgs.connexionswing_prod.apache.modules ++
165 mypkgs.ympd.apache.modules ++
166 pkgs.lib.lists.flatten (pkgs.lib.attrsets.mapAttrsToList (n: v: v.modules) apacheConfig) ++
168 extraConfig = builtins.concatStringsSep "\n"
169 (pkgs.lib.attrsets.mapAttrsToList (n: v: v.extraConfig) apacheConfig);
171 (withSSL "eldiron" // {
172 listen = [ { ip = "*"; port = 443; } ];
173 hostName = "eldiron.immae.eu";
174 documentRoot = ./www;
176 DirectoryIndex index.htm
179 (withSSL "eldiron" // {
180 listen = [ { ip = "*"; port = 443; } ];
181 hostName = "db-1.immae.eu";
183 extraConfig = builtins.concatStringsSep "\n" [
184 mypkgs.adminer.apache.vhostConf
187 (withSSL "eldiron" // {
188 listen = [ { ip = "*"; port = 443; } ];
189 hostName = "tools.immae.eu";
191 extraConfig = builtins.concatStringsSep "\n" [
192 mypkgs.adminer.apache.vhostConf
193 mypkgs.ympd.apache.vhostConf
196 (withSSL "eldiron" // {
197 listen = [ { ip = "*"; port = 443; } ];
198 hostName = "connexionswing.immae.eu";
199 serverAliases = [ "sandetludo.immae.eu" ];
200 documentRoot = mypkgs.connexionswing_dev.webRoot;
201 extraConfig = builtins.concatStringsSep "\n" [
202 mypkgs.connexionswing_dev.apache.vhostConf
205 { # Should go last, default fallback
206 listen = [ { ip = "*"; port = 80; } ];
207 hostName = "redirectSSL";
208 serverAliases = [ "*" ];
210 documentRoot = "/var/lib/acme/acme-challenge";
213 RewriteCond "%{REQUEST_URI}" "!^/\.well-known"
214 RewriteRule ^(.+) https://%{HTTP_HOST}$1 [R=301]
215 # To redirect in specific "VirtualHost *:80", do
216 # RedirectMatch 301 ^/((?!\.well-known.*$).*)$ https://host/$1
217 # rather than rewrite
223 security.pam.services = let
224 pam_ldap = pkgs.pam_ldap;
225 pam_ldap_mysql = assert mylibs.checkEnv "NIXOPS_MYSQL_PAM_PASSWORD";
226 pkgs.writeText "mysql.conf" ''
229 binddn cn=mysql,cn=pam,ou=services,dc=immae,dc=eu
230 bindpw ${builtins.getEnv "NIXOPS_MYSQL_PAM_PASSWORD"}
231 pam_filter memberOf=cn=users,cn=mysql,cn=pam,ou=services,dc=immae,dc=eu
237 # https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/
238 auth required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql}
239 account required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql}
245 services.redis = rec {
248 unixSocket = "/run/redis/redis.sock";
255 # FIXME: initial sync
257 # FIXME: restart after pam
258 # FIXME: pam access doesn’t work (because of php module)
260 services.mysql = rec {
262 package = pkgs.mariadb.overrideAttrs(old: rec {
263 cmakeFlags = old.cmakeFlags ++ [ "-DWITH_AUTHENTICATION_PAM=ON" ];
264 buildInputs = old.buildInputs ++ [ pkgs.pam ];
268 # FIXME: initial sync
271 services.postgresql = rec {
273 package = pkgs.postgresql100.overrideAttrs(old: rec {
274 passthru = old.passthru // { psqlSchema = "11.0"; };
275 name = "postgresql-11.1";
276 src = pkgs.fetchurl {
277 url = "mirror://postgresql/source/v11.1/${name}.tar.bz2";
278 sha256 = "026v0sicsh7avzi45waf8shcbhivyxmi7qgn9fd1x0vl520mx0ch";
283 max_connections = 100
285 shared_buffers = 128MB
288 log_timezone = 'Europe/Paris'
289 datestyle = 'iso, mdy'
290 timezone = 'Europe/Paris'
291 lc_messages = 'en_US.UTF-8'
292 lc_monetary = 'en_US.UTF-8'
293 lc_numeric = 'en_US.UTF-8'
294 lc_time = 'en_US.UTF-8'
295 default_text_search_config = 'pg_catalog.english'
297 # ssl_cert_file = '/var/lib/acme/eldiron/fullchain.pem'
298 # ssl_key_file = '/var/lib/acme/eldiron/key.pem'
301 local all postgres ident
303 host all all 178.33.252.96/32 md5
304 host all all 188.165.209.148/32 md5
305 #host all all all pam