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 = 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" \
46 ${config.services.phpfpm.phpPackage}/bin/php \
47 -c ${config.services.phpfpm.phpPackage}/etc/php.ini \
56 security.acme.certs = {
58 webroot = "/var/lib/acme/acme-challenge";
59 email = "ismael@bouya.org";
60 domain = "eldiron.immae.eu";
61 plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ];
63 systemctl reload httpd.service
66 "db-1.immae.eu" = null;
67 "tools.immae.eu" = null;
68 "connexionswing.immae.eu" = null;
69 "sandetludo.immae.eu" = null;
70 "cloud.immae.eu" = null;
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" ];
79 # systemctl reload httpd.service
82 # "www.connexionswing.com" = null;
83 # "sandetludo.com" = null;
84 # "www.sandetludo.com" = null;
89 services.openssh.extraConfig = ''
90 AuthorizedKeysCommand /etc/ssh/ldap_authorized_keys
91 AuthorizedKeysCommandUser nobody
94 # FIXME: after initial install, need to
95 # (1) copy rc file (adjust gitolite_ldap_groups.sh)
96 # (2) (mark old readonly and) sync repos except gitolite-admin
97 # rsync -av --exclude=gitolite-admin.git old:/var/lib/gitolite/repositories /var/lib/gitolite/
98 # chown -R gitolite:gitolite /var/lib/gitolite
99 # (3) push force the gitolite-admin to new location (from external point)
100 # Don't use an existing key, it will take precedence over
102 # (4) su -u gitolite gitolite setup
103 services.gitolite = {
105 # FIXME: key from ./ssh
106 adminPubkey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDXqRbiHw7QoHADNIEuo4nUT9fSOIEBMdJZH0bkQAxXyJFyCM1IMz0pxsHV0wu9tdkkr36bPEUj2aV5bkYLBN6nxcV2Y49X8bjOSCPfx3n6Own1h+NeZVBj4ZByrFmqCbTxUJIZ2bZKcWOFncML39VmWdsVhNjg0X4NBBehqXRIKr2gt3E/ESAxTYJFm0BnU0baciw9cN0bsRGqvFgf5h2P48CIAfwhVcGmPQnnAwabnosYQzRWxR0OygH5Kd8mePh6FheIRIigfXsDO8f/jdxwut8buvNIf3m5EBr3tUbTsvM+eV3M5vKGt7sk8T64DVtepTSdOOWtp+47ktsnHOMh immae@immae.eu";
109 services.ympd = mypkgs.ympd.config // { enable = true; };
112 # /!\ phppackage is used in nextcloud configuation
115 extension=${pkgs.phpPackages.redis}/lib/php/extensions/redis.so
117 extension=${pkgs.phpPackages.apcu}/lib/php/extensions/apcu.so
123 adminer = mypkgs.adminer.phpFpm.pool;
124 connexionswing_dev = mypkgs.connexionswing_dev.phpFpm.pool;
125 connexionswing_prod = mypkgs.connexionswing_prod.phpFpm.pool;
126 nextcloud = mypkgs.nextcloud.phpFpm.pool;
130 system.activationScripts = {
131 connexionswing_dev = mypkgs.connexionswing_dev.activationScript;
132 connexionswing_prod = mypkgs.connexionswing_prod.activationScript;
133 nextcloud = mypkgs.nextcloud.activationScript;
135 install -d -m 0755 /var/lib/acme/acme-challenge
139 chown redis /run/redis
142 assert mylibs.checkEnv "NIXOPS_GITOLITE_LDAP_PASSWORD";
144 gitolite_ldap_groups = mylibs.wrap {
145 name = "gitolite_ldap_groups.sh";
146 file = ./packages/gitolite_ldap_groups.sh;
148 LDAP_PASS = builtins.getEnv "NIXOPS_GITOLITE_LDAP_PASSWORD";
150 paths = [ pkgs.openldap pkgs.stdenv.shellPackage pkgs.gnugrep pkgs.coreutils ];
155 if [ -d /var/lib/gitolite ]; then
156 ln -sf ${gitolite_ldap_groups} /var/lib/gitolite/gitolite_ldap_groups.sh
162 environment.etc."ssh/ldap_authorized_keys" = let
163 ldap_authorized_keys =
164 assert mylibs.checkEnv "NIXOPS_SSHD_LDAP_PASSWORD";
166 name = "ldap_authorized_keys";
167 file = ./ldap_authorized_keys.sh;
169 LDAP_PASS = builtins.getEnv "NIXOPS_SSHD_LDAP_PASSWORD";
170 GITOLITE_SHELL = "${pkgs.gitolite}/bin/gitolite-shell";
171 ECHO = "${pkgs.coreutils}/bin/echo";
173 paths = [ pkgs.openldap pkgs.stdenv.shellPackage pkgs.gnugrep pkgs.gnused pkgs.coreutils ];
179 source = ldap_authorized_keys;
185 sslServerCert = "/var/lib/acme/${domain}/cert.pem";
186 sslServerKey = "/var/lib/acme/${domain}/key.pem";
187 sslServerChain = "/var/lib/acme/${domain}/fullchain.pem";
191 modules = [ "deflate" "filter" ];
193 AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
197 modules = [ "ldap" "authnz_ldap" ];
198 extraConfig = assert mylibs.checkEnv "NIXOPS_HTTP_LDAP_PASSWORD"; ''
199 <IfModule ldap_module>
200 LDAPSharedCacheSize 500000
201 LDAPCacheEntries 1024
203 LDAPOpCacheEntries 1024
208 <IfModule authnz_ldap_module>
209 AuthLDAPURL ldap://ldap.immae.eu:389/dc=immae,dc=eu
210 AuthLDAPBindDN cn=httpd,ou=services,dc=immae,dc=eu
211 AuthLDAPBindPassword "${builtins.getEnv "NIXOPS_HTTP_LDAP_PASSWORD"}"
213 AuthName "Authentification requise (Acces LDAP)"
214 AuthBasicProvider ldap
222 logPerVirtualHost = true;
223 multiProcessingModule = "worker";
224 adminAddr = "httpd@immae.eu";
226 # FIXME: voir les autres modules:
231 # proxy_connect_module
235 # proxy_balancer_module
236 # proxy_express_module
237 # lbmethod_byrequests_module
238 # lbmethod_bytraffic_module
239 # lbmethod_bybusyness_module
240 # lbmethod_heartbeat_module
242 extraModules = pkgs.lib.lists.unique (
243 mypkgs.adminer.apache.modules ++
244 mypkgs.nextcloud.apache.modules ++
245 mypkgs.connexionswing_dev.apache.modules ++
246 mypkgs.connexionswing_prod.apache.modules ++
247 mypkgs.ympd.apache.modules ++
248 pkgs.lib.lists.flatten (pkgs.lib.attrsets.mapAttrsToList (n: v: v.modules) apacheConfig) ++
250 extraConfig = builtins.concatStringsSep "\n"
251 (pkgs.lib.attrsets.mapAttrsToList (n: v: v.extraConfig) apacheConfig);
253 (withSSL "eldiron" // {
254 listen = [ { ip = "*"; port = 443; } ];
255 hostName = "eldiron.immae.eu";
256 documentRoot = ./www;
258 DirectoryIndex index.htm
261 (withSSL "eldiron" // {
262 listen = [ { ip = "*"; port = 443; } ];
263 hostName = "db-1.immae.eu";
265 extraConfig = builtins.concatStringsSep "\n" [
266 mypkgs.adminer.apache.vhostConf
269 (withSSL "eldiron" // {
270 listen = [ { ip = "*"; port = 443; } ];
271 hostName = "tools.immae.eu";
273 extraConfig = builtins.concatStringsSep "\n" [
274 mypkgs.adminer.apache.vhostConf
275 mypkgs.ympd.apache.vhostConf
278 (withSSL "eldiron" // {
279 listen = [ { ip = "*"; port = 443; } ];
280 hostName = "connexionswing.immae.eu";
281 serverAliases = [ "sandetludo.immae.eu" ];
282 documentRoot = mypkgs.connexionswing_dev.webRoot;
283 extraConfig = builtins.concatStringsSep "\n" [
284 mypkgs.connexionswing_dev.apache.vhostConf
287 (withSSL "eldiron" // {
288 listen = [ { ip = "*"; port = 443; } ];
289 hostName = "cloud.immae.eu";
290 documentRoot = mypkgs.nextcloud.webRoot;
291 extraConfig = builtins.concatStringsSep "\n" [
292 mypkgs.nextcloud.apache.vhostConf
295 { # Should go last, default fallback
296 listen = [ { ip = "*"; port = 80; } ];
297 hostName = "redirectSSL";
298 serverAliases = [ "*" ];
300 documentRoot = "/var/lib/acme/acme-challenge";
303 RewriteCond "%{REQUEST_URI}" "!^/\.well-known"
304 RewriteRule ^(.+) https://%{HTTP_HOST}$1 [R=301]
305 # To redirect in specific "VirtualHost *:80", do
306 # RedirectMatch 301 ^/((?!\.well-known.*$).*)$ https://host/$1
307 # rather than rewrite
313 security.pam.services = let
314 pam_ldap = pkgs.pam_ldap;
315 pam_ldap_mysql = assert mylibs.checkEnv "NIXOPS_MYSQL_PAM_PASSWORD";
316 pkgs.writeText "mysql.conf" ''
319 binddn cn=mysql,cn=pam,ou=services,dc=immae,dc=eu
320 bindpw ${builtins.getEnv "NIXOPS_MYSQL_PAM_PASSWORD"}
321 pam_filter memberOf=cn=users,cn=mysql,cn=pam,ou=services,dc=immae,dc=eu
327 # https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/
328 auth required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql}
329 account required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql}
335 services.redis = rec {
338 unixSocket = "/run/redis/redis.sock";
345 # FIXME: initial sync
347 # FIXME: restart after pam
348 # FIXME: pam access doesn’t work (because of php module)
350 services.mysql = rec {
352 package = pkgs.mariadb.overrideAttrs(old: rec {
353 cmakeFlags = old.cmakeFlags ++ [ "-DWITH_AUTHENTICATION_PAM=ON" ];
354 buildInputs = old.buildInputs ++ [ pkgs.pam ];
358 # FIXME: initial sync
361 services.postgresql = rec {
363 package = pkgs.postgresql100.overrideAttrs(old: rec {
364 passthru = old.passthru // { psqlSchema = "11.0"; };
365 name = "postgresql-11.1";
366 src = pkgs.fetchurl {
367 url = "mirror://postgresql/source/v11.1/${name}.tar.bz2";
368 sha256 = "026v0sicsh7avzi45waf8shcbhivyxmi7qgn9fd1x0vl520mx0ch";
373 max_connections = 100
375 shared_buffers = 128MB
378 log_timezone = 'Europe/Paris'
379 datestyle = 'iso, mdy'
380 timezone = 'Europe/Paris'
381 lc_messages = 'en_US.UTF-8'
382 lc_monetary = 'en_US.UTF-8'
383 lc_numeric = 'en_US.UTF-8'
384 lc_time = 'en_US.UTF-8'
385 default_text_search_config = 'pg_catalog.english'
387 # ssl_cert_file = '/var/lib/acme/eldiron/fullchain.pem'
388 # ssl_key_file = '/var/lib/acme/eldiron/key.pem'
391 local all postgres ident
393 host all all 178.33.252.96/32 md5
394 host all all 188.165.209.148/32 md5
395 #host all all all pam