3 description = "Immae's network";
7 eldiron = { config, pkgs, ... }:
8 with import ../libs.nix;
10 mypkgs = pkgs.callPackage ./packages.nix {
11 inherit checkEnv fetchedGitPrivate fetchedGithub;
15 # FIXME: they are not overriden in packages.nix
16 # (see nix-store -q --tree /nix/var/nix/profiles/system)
17 nixpkgs.config.packageOverrides = oldpkgs: rec {
18 gitolite = nixpkgs_unstable.gitolite;
19 gitweb = oldpkgs.gitweb.overrideAttrs(old: {
20 installPhase = old.installPhase + ''
21 cp -r ${./packages/gitweb} $out/gitweb-theme;
24 postgresql = postgresql111;
25 postgresql111 = oldpkgs.postgresql100.overrideAttrs(old: rec {
26 passthru = old.passthru // { psqlSchema = "11.0"; };
27 name = "postgresql-11.1";
29 url = "mirror://postgresql/source/v11.1/${name}.tar.bz2";
30 sha256 = "026v0sicsh7avzi45waf8shcbhivyxmi7qgn9fd1x0vl520mx0ch";
34 mariadbPAM = oldpkgs.mariadb.overrideAttrs(old: rec {
35 cmakeFlags = old.cmakeFlags ++ [ "-DWITH_AUTHENTICATION_PAM=ON" ];
36 buildInputs = old.buildInputs ++ [ pkgs.pam ];
43 allowedTCPPorts = [ 22 80 443 3306 5432 9418 ];
48 targetEnv = "hetzner";
50 #robotUser = "defined in HETZNER_ROBOT_USER";
51 #robotPass = "defined in HETZNER_ROBOT_PASS";
52 mainIPv4 = "176.9.151.89";
54 clearpart --all --initlabel --drives=sda,sdb
56 part swap1 --recommended --label=swap1 --fstype=swap --ondisk=sda
57 part swap2 --recommended --label=swap2 --fstype=swap --ondisk=sdb
59 part raid.1 --grow --ondisk=sda
60 part raid.2 --grow --ondisk=sdb
62 raid / --level=1 --device=md0 --fstype=ext4 --label=root raid.1 raid.2
67 environment.systemPackages = let
68 # FIXME: move it to nextcloud
69 occ = pkgs.writeScriptBin "nextcloud-occ" ''
70 #! ${pkgs.stdenv.shell}
71 cd ${mypkgs.nextcloud.webRoot}
72 NEXTCLOUD_CONFIG_DIR="${mypkgs.nextcloud.webRoot}/config" \
74 ${config.services.phpfpm.phpPackage}/bin/php \
75 -c ${config.services.phpfpm.phpPackage}/etc/php.ini \
84 security.acme.certs = {
86 webroot = "/var/lib/acme/acme-challenge";
87 email = "ismael@bouya.org";
88 domain = "eldiron.immae.eu";
89 plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ];
91 systemctl reload httpd.service
94 "db-1.immae.eu" = null;
95 "git.immae.eu" = null;
96 "tools.immae.eu" = null;
97 "connexionswing.immae.eu" = null;
98 "sandetludo.immae.eu" = null;
99 "cloud.immae.eu" = null;
102 # "connexionswing" = {
103 # webroot = "/var/lib/acme/acme-challenge";
104 # email = "ismael@bouya.org";
105 # domain = "connexionswing.com";
106 # plugins = [ "cert.pem" "chain.pem" "fullchain.pem" "full.pem" "key.pem" "account_key.json" ];
108 # systemctl reload httpd.service
111 # "www.connexionswing.com" = null;
112 # "sandetludo.com" = null;
113 # "www.sandetludo.com" = null;
118 services.openssh.extraConfig = ''
119 AuthorizedKeysCommand /etc/ssh/ldap_authorized_keys
120 AuthorizedKeysCommandUser nobody
123 users.users.wwwrun.extraGroups = [ "gitolite" ];
125 users.users.gitolite.packages = let
126 python-packages = python-packages: with python-packages; [
132 (pkgs.python3.withPackages python-packages)
134 # FIXME: after initial install, need to
135 # (1) copy rc file (adjust gitolite_ldap_groups.sh)
136 # (2) (mark old readonly and) sync repos except gitolite-admin
137 # rsync -av --exclude=gitolite-admin.git old:/var/lib/gitolite/repositories /var/lib/gitolite/
138 # chown -R gitolite:gitolite /var/lib/gitolite
139 # (3) push force the gitolite-admin to new location (from external point)
140 # Don't use an existing key, it will take precedence over
142 # (4) su -u gitolite gitolite setup
143 services.gitolite = {
145 # FIXME: key from ./ssh
146 adminPubkey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDXqRbiHw7QoHADNIEuo4nUT9fSOIEBMdJZH0bkQAxXyJFyCM1IMz0pxsHV0wu9tdkkr36bPEUj2aV5bkYLBN6nxcV2Y49X8bjOSCPfx3n6Own1h+NeZVBj4ZByrFmqCbTxUJIZ2bZKcWOFncML39VmWdsVhNjg0X4NBBehqXRIKr2gt3E/ESAxTYJFm0BnU0baciw9cN0bsRGqvFgf5h2P48CIAfwhVcGmPQnnAwabnosYQzRWxR0OygH5Kd8mePh6FheIRIigfXsDO8f/jdxwut8buvNIf3m5EBr3tUbTsvM+eV3M5vKGt7sk8T64DVtepTSdOOWtp+47ktsnHOMh immae@immae.eu";
149 services.ympd = mypkgs.ympd.config // { enable = true; };
152 # /!\ phppackage is used in nextcloud configuation
155 extension=${pkgs.phpPackages.redis}/lib/php/extensions/redis.so
157 extension=${pkgs.phpPackages.apcu}/lib/php/extensions/apcu.so
163 adminer = mypkgs.adminer.phpFpm.pool;
164 connexionswing_dev = mypkgs.connexionswing_dev.phpFpm.pool;
165 connexionswing_prod = mypkgs.connexionswing_prod.phpFpm.pool;
166 nextcloud = mypkgs.nextcloud.phpFpm.pool;
167 mantisbt = mypkgs.mantisbt.phpFpm.pool;
171 system.activationScripts = {
172 connexionswing_dev = mypkgs.connexionswing_dev.activationScript;
173 connexionswing_prod = mypkgs.connexionswing_prod.activationScript;
174 nextcloud = mypkgs.nextcloud.activationScript;
176 install -d -m 0755 /var/lib/acme/acme-challenge
180 chown redis /run/redis
183 assert checkEnv "NIXOPS_GITOLITE_LDAP_PASSWORD";
185 gitolite_ldap_groups = wrap {
186 name = "gitolite_ldap_groups.sh";
187 file = ./packages/gitolite_ldap_groups.sh;
189 LDAP_PASS = builtins.getEnv "NIXOPS_GITOLITE_LDAP_PASSWORD";
191 paths = [ pkgs.openldap pkgs.stdenv.shellPackage pkgs.gnugrep pkgs.coreutils ];
196 if [ -d /var/lib/gitolite ]; then
197 ln -sf ${gitolite_ldap_groups} /var/lib/gitolite/gitolite_ldap_groups.sh
198 chmod g+rx /var/lib/gitolite
200 if [ -f /var/lib/gitolite/projects.list ]; then
201 chmod g+r /var/lib/gitolite/projects.list
207 environment.etc."ssh/ldap_authorized_keys" = let
208 ldap_authorized_keys =
209 assert checkEnv "NIXOPS_SSHD_LDAP_PASSWORD";
211 name = "ldap_authorized_keys";
212 file = ./ldap_authorized_keys.sh;
214 LDAP_PASS = builtins.getEnv "NIXOPS_SSHD_LDAP_PASSWORD";
215 GITOLITE_SHELL = "${pkgs.gitolite}/bin/gitolite-shell";
216 ECHO = "${pkgs.coreutils}/bin/echo";
218 paths = [ pkgs.openldap pkgs.stdenv.shellPackage pkgs.gnugrep pkgs.gnused pkgs.coreutils ];
224 source = ldap_authorized_keys;
227 services.gitDaemon = {
231 basePath = "${mypkgs.git.web.varDir}/repositories";
237 sslServerCert = "/var/lib/acme/${domain}/cert.pem";
238 sslServerKey = "/var/lib/acme/${domain}/key.pem";
239 sslServerChain = "/var/lib/acme/${domain}/fullchain.pem";
243 modules = [ "deflate" "filter" ];
245 AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
249 modules = [ "ldap" "authnz_ldap" ];
250 extraConfig = assert checkEnv "NIXOPS_HTTP_LDAP_PASSWORD"; ''
251 <IfModule ldap_module>
252 LDAPSharedCacheSize 500000
253 LDAPCacheEntries 1024
255 LDAPOpCacheEntries 1024
260 <IfModule authnz_ldap_module>
261 AuthLDAPURL ldap://ldap.immae.eu:389/dc=immae,dc=eu
262 AuthLDAPBindDN cn=httpd,ou=services,dc=immae,dc=eu
263 AuthLDAPBindPassword "${builtins.getEnv "NIXOPS_HTTP_LDAP_PASSWORD"}"
265 AuthName "Authentification requise (Acces LDAP)"
266 AuthBasicProvider ldap
274 logPerVirtualHost = true;
275 multiProcessingModule = "worker";
276 adminAddr = "httpd@immae.eu";
278 # FIXME: voir les autres modules:
283 # proxy_connect_module
287 # proxy_balancer_module
288 # proxy_express_module
289 # lbmethod_byrequests_module
290 # lbmethod_bytraffic_module
291 # lbmethod_bybusyness_module
292 # lbmethod_heartbeat_module
294 extraModules = pkgs.lib.lists.unique (
295 mypkgs.adminer.apache.modules ++
296 mypkgs.nextcloud.apache.modules ++
297 mypkgs.connexionswing_dev.apache.modules ++
298 mypkgs.connexionswing_prod.apache.modules ++
299 mypkgs.ympd.apache.modules ++
300 mypkgs.git.web.apache.modules ++
301 mypkgs.mantisbt.apache.modules ++
302 pkgs.lib.lists.flatten (pkgs.lib.attrsets.mapAttrsToList (n: v: v.modules) apacheConfig) ++
304 extraConfig = builtins.concatStringsSep "\n"
305 (pkgs.lib.attrsets.mapAttrsToList (n: v: v.extraConfig) apacheConfig);
307 (withSSL "eldiron" // {
308 listen = [ { ip = "*"; port = 443; } ];
309 hostName = "eldiron.immae.eu";
310 documentRoot = ./www;
312 DirectoryIndex index.htm
315 (withSSL "eldiron" // {
316 listen = [ { ip = "*"; port = 443; } ];
317 hostName = "db-1.immae.eu";
319 extraConfig = builtins.concatStringsSep "\n" [
320 mypkgs.adminer.apache.vhostConf
323 (withSSL "eldiron" // {
324 listen = [ { ip = "*"; port = 443; } ];
325 hostName = "tools.immae.eu";
327 extraConfig = builtins.concatStringsSep "\n" [
328 mypkgs.adminer.apache.vhostConf
329 mypkgs.ympd.apache.vhostConf
332 (withSSL "eldiron" // {
333 listen = [ { ip = "*"; port = 443; } ];
334 hostName = "connexionswing.immae.eu";
335 serverAliases = [ "sandetludo.immae.eu" ];
336 documentRoot = mypkgs.connexionswing_dev.webRoot;
337 extraConfig = builtins.concatStringsSep "\n" [
338 mypkgs.connexionswing_dev.apache.vhostConf
341 (withSSL "eldiron" // {
342 listen = [ { ip = "*"; port = 443; } ];
343 hostName = "cloud.immae.eu";
344 documentRoot = mypkgs.nextcloud.webRoot;
345 extraConfig = builtins.concatStringsSep "\n" [
346 mypkgs.nextcloud.apache.vhostConf
349 (withSSL "eldiron" // {
350 listen = [ { ip = "*"; port = 443; } ];
351 hostName = "git.immae.eu";
352 documentRoot = mypkgs.git.web.webRoot;
353 extraConfig = builtins.concatStringsSep "\n" [
354 mypkgs.git.web.apache.vhostConf
355 mypkgs.mantisbt.apache.vhostConf
358 RewriteCond %{REQUEST_URI} ^/releases
359 RewriteRule /releases(.*) https://release.immae.eu$1 [P,L]
362 { # Should go last, default fallback
363 listen = [ { ip = "*"; port = 80; } ];
364 hostName = "redirectSSL";
365 serverAliases = [ "*" ];
367 documentRoot = "/var/lib/acme/acme-challenge";
370 RewriteCond "%{REQUEST_URI}" "!^/\.well-known"
371 RewriteRule ^(.+) https://%{HTTP_HOST}$1 [R=301]
372 # To redirect in specific "VirtualHost *:80", do
373 # RedirectMatch 301 ^/((?!\.well-known.*$).*)$ https://host/$1
374 # rather than rewrite
380 security.pam.services = let
381 pam_ldap = pkgs.pam_ldap;
382 pam_ldap_mysql = assert checkEnv "NIXOPS_MYSQL_PAM_PASSWORD";
383 pkgs.writeText "mysql.conf" ''
386 binddn cn=mysql,cn=pam,ou=services,dc=immae,dc=eu
387 bindpw ${builtins.getEnv "NIXOPS_MYSQL_PAM_PASSWORD"}
388 pam_filter memberOf=cn=users,cn=mysql,cn=pam,ou=services,dc=immae,dc=eu
394 # https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/
395 auth required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql}
396 account required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql}
402 services.redis = rec {
405 unixSocket = "/run/redis/redis.sock";
412 # FIXME: initial sync
414 # FIXME: restart after pam
415 # FIXME: pam access doesn’t work (because of php module)
417 services.mysql = rec {
419 package = pkgs.mariadb;
422 # FIXME: initial sync
425 services.postgresql = rec {
427 package = pkgs.postgresql;
430 max_connections = 100
432 shared_buffers = 128MB
435 log_timezone = 'Europe/Paris'
436 datestyle = 'iso, mdy'
437 timezone = 'Europe/Paris'
438 lc_messages = 'en_US.UTF-8'
439 lc_monetary = 'en_US.UTF-8'
440 lc_numeric = 'en_US.UTF-8'
441 lc_time = 'en_US.UTF-8'
442 default_text_search_config = 'pg_catalog.english'
444 # ssl_cert_file = '/var/lib/acme/eldiron/fullchain.pem'
445 # ssl_key_file = '/var/lib/acme/eldiron/key.pem'
448 local all postgres ident
450 host all all samehost md5
451 host all all 178.33.252.96/32 md5
452 host all all 188.165.209.148/32 md5
453 #host all all all pam