]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - virtual/eldiron.nix
Put adminer configuration in its package
[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 in
10 {
11 networking = {
12 firewall = {
13 enable = true;
14 allowedTCPPorts = [ 22 80 443 3306 5432 ];
15 };
16 };
17
18 deployment = {
19 targetEnv = "hetzner";
20 hetzner = {
21 #robotUser = "defined in HETZNER_ROBOT_USER";
22 #robotPass = "defined in HETZNER_ROBOT_PASS";
23 mainIPv4 = "176.9.151.89";
24 partitions = ''
25 clearpart --all --initlabel --drives=sda,sdb
26
27 part swap1 --recommended --label=swap1 --fstype=swap --ondisk=sda
28 part swap2 --recommended --label=swap2 --fstype=swap --ondisk=sdb
29
30 part raid.1 --grow --ondisk=sda
31 part raid.2 --grow --ondisk=sdb
32
33 raid / --level=1 --device=md0 --fstype=ext4 --label=root raid.1 raid.2
34 '';
35 };
36 };
37
38 # FIXME: how to run it? currently set as timer
39 security.acme.certs = {
40 "eldiron" = {
41 webroot = "/var/lib/acme/acme-challenge";
42 email = "ismael@bouya.org";
43 domain = "eldiron.immae.eu";
44 extraDomains = {
45 "db-1.immae.eu" = null;
46 };
47 };
48 };
49
50 # FIXME: open_basedir
51 services.phpfpm = {
52 extraConfig = ''
53 log_level = notice
54 '';
55 poolConfigs = {
56 adminer = mypkgs.adminer.phpFpm.pool;
57 www = ''
58 listen = /var/run/phpfpm/www.sock
59 user = wwwrun
60 group = wwwrun
61 listen.owner = wwwrun
62 listen.group = wwwrun
63 pm = ondemand
64 pm.max_children = 5
65 pm.process_idle_timeout = 60
66 ;php_admin_flag[log_errors] = on
67 php_admin_value[open_basedir] = "/var/www"
68 '';
69 };
70 };
71
72 services.httpd = let
73 withSSL = domain: {
74 enableSSL = true;
75 sslServerCert = "/var/lib/acme/${domain}/full.pem"; # FIXME: cert only?
76 sslServerKey = "/var/lib/acme/${domain}/key.pem";
77 sslServerChain = "/var/lib/acme/${domain}/fullchain.pem";
78 };
79 in rec {
80 enable = true;
81 logPerVirtualHost = true;
82 multiProcessingModule = "worker";
83 adminAddr = "httpd@immae.eu";
84 extraModules = [
85 "proxy_fcgi" # for PHP
86 ];
87 virtualHosts = [
88 (withSSL "eldiron" // {
89 listen = [ { ip = "*"; port = 443; } ];
90 hostName = "eldiron.immae.eu";
91 # FIXME: directory needs to exist
92 documentRoot = "/var/www";
93 })
94 (withSSL "eldiron" // {
95 listen = [ { ip = "*"; port = 443; } ];
96 hostName = "db-1.immae.eu";
97 documentRoot = null;
98 extraConfig = builtins.concatStringsSep "\n" [
99 mypkgs.adminer.apacheConf
100 ];
101 })
102 { # Should go last, default fallback
103 listen = [ { ip = "*"; port = 80; } ];
104 hostName = "redirectSSL";
105 serverAliases = [ "*" ];
106 enableSSL = false;
107 # FIXME: directory needs to exist
108 documentRoot = "/var/lib/acme/acme-challenge";
109 extraConfig = ''
110 RewriteEngine on
111 RewriteCond "%{REQUEST_URI}" "!^/\.well-known"
112 RewriteRule ^(.+) https://%{HTTP_HOST}$1 [R=301]
113 # To redirect in specific "VirtualHost *:80", do
114 # RedirectMatch 301 ^/((?!\.well-known.*$).*)$ https://host/$1
115 # rather than rewrite
116 '';
117 }
118 ];
119 };
120
121 # FIXME: environment variables ?
122 security.pam.services = let
123 pam_ldap = pkgs.pam_ldap;
124 pam_ldap_mysql = pkgs.writeText "mysql.conf" ''
125 host ldap.immae.eu
126 base dc=immae,dc=eu
127 binddn cn=mysql,cn=pam,ou=services,dc=immae,dc=eu
128 bindpw ${builtins.getEnv "NIXOPS_MYSQL_PAM_PASSWORD"}
129 pam_filter memberOf=cn=users,cn=mysql,cn=pam,ou=services,dc=immae,dc=eu
130 '';
131 in [
132 {
133 name = "mysql";
134 text = ''
135 # https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/
136 auth required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql}
137 account required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql}
138 '';
139 }
140 ];
141
142 # FIXME: initial sync
143 # FIXME: backup
144 # FIXME: restart after pam
145 # FIXME: pam access doesn’t work (because of php module)
146 # FIXME: ssl
147 services.mysql = rec {
148 enable = true;
149 package = pkgs.mariadb.overrideAttrs(old: rec {
150 cmakeFlags = old.cmakeFlags ++ [ "-DWITH_AUTHENTICATION_PAM=ON" ];
151 buildInputs = old.buildInputs ++ [ pkgs.pam ];
152 });
153 };
154
155 # FIXME: initial sync
156 # FIXME: backup
157 # FIXME: ssl
158 services.postgresql = rec {
159 enable = true;
160 package = pkgs.postgresql100.overrideAttrs(old: rec {
161 passthru = old.passthru // { psqlSchema = "11.0"; };
162 name = "postgresql-11.1";
163 src = pkgs.fetchurl {
164 url = "mirror://postgresql/source/v11.1/${name}.tar.bz2";
165 sha256 = "026v0sicsh7avzi45waf8shcbhivyxmi7qgn9fd1x0vl520mx0ch";
166 };
167 });
168 enableTCPIP = true;
169 extraConfig = ''
170 max_connections = 100
171 wal_level = logical
172 shared_buffers = 128MB
173 max_wal_size = 1GB
174 min_wal_size = 80MB
175 log_timezone = 'Europe/Paris'
176 datestyle = 'iso, mdy'
177 timezone = 'Europe/Paris'
178 lc_messages = 'en_US.UTF-8'
179 lc_monetary = 'en_US.UTF-8'
180 lc_numeric = 'en_US.UTF-8'
181 lc_time = 'en_US.UTF-8'
182 default_text_search_config = 'pg_catalog.english'
183 # ssl = on
184 # ssl_cert_file = '/var/lib/acme/eldiron/fullchain.pem'
185 # ssl_key_file = '/var/lib/acme/eldiron/key.pem'
186 '';
187 authentication = ''
188 local all postgres ident
189 local all all md5
190 host all all 178.33.252.96/32 md5
191 host all all 188.165.209.148/32 md5
192 #host all all all pam
193 '';
194 };
195 };
196 }