]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - virtual/eldiron.nix
Add mysql
[perso/Immae/Config/Nix.git] / virtual / eldiron.nix
CommitLineData
a1bb33c4
IB
1{
2 network = {
3 description = "Immae's network";
4 enableRollback = true;
5 };
6
7 eldiron = { config, pkgs, ... }: {
8 networking = {
9 firewall = {
10 enable = true;
dedf591d 11 allowedTCPPorts = [ 22 80 443 3306 5432 ];
a1bb33c4
IB
12 };
13 };
14
15 deployment = {
16 targetEnv = "hetzner";
17 hetzner = {
18 #robotUser = "defined in HETZNER_ROBOT_USER";
19 #robotPass = "defined in HETZNER_ROBOT_PASS";
20 mainIPv4 = "176.9.151.89";
21 partitions = ''
22 clearpart --all --initlabel --drives=sda,sdb
23
24 part swap1 --recommended --label=swap1 --fstype=swap --ondisk=sda
25 part swap2 --recommended --label=swap2 --fstype=swap --ondisk=sdb
26
27 part raid.1 --grow --ondisk=sda
28 part raid.2 --grow --ondisk=sdb
29
30 raid / --level=1 --device=md0 --fstype=ext4 --label=root raid.1 raid.2
31 '';
32 };
33 };
34
35 # FIXME: how to run it? currently set as timer
36 security.acme.certs = {
37 "eldiron" = {
38 webroot = "/var/lib/acme/acme-challenge";
39 email = "ismael@bouya.org";
40 domain = "eldiron.immae.eu";
41 extraDomains = {
42 "db-1.immae.eu" = null;
43 };
44 };
45 };
46
47 services.nginx = rec {
48 enable = true;
49 virtualHosts = {
50 "_" = {
51 serverName = "_";
52 useACMEHost = "eldiron";
53 };
54 "eldiron.immae.eu" = {
55 forceSSL = true;
56 useACMEHost = "eldiron";
57 locations."/" = {
58 # FIXME: directory needs to exist
59 root = "/var/www";
60 };
61 };
62 };
63 };
64
dedf591d
IB
65 # FIXME: environment variables ?
66 security.pam.services = let
67 pam_ldap = pkgs.pam_ldap;
68 pam_ldap_mysql = pkgs.writeText "mysql.conf" ''
69 host ldap.immae.eu
70 base dc=immae,dc=eu
71 binddn cn=mysql,cn=pam,ou=services,dc=immae,dc=eu
72 bindpw ${builtins.getEnv "NIXOPS_MYSQL_PAM_PASSWORD"}
73 pam_filter memberOf=cn=users,cn=mysql,cn=pam,ou=services,dc=immae,dc=eu
74 '';
75 in [
76 {
77 name = "mysql";
78 text = ''
79 # https://mariadb.com/kb/en/mariadb/pam-authentication-plugin/
80 auth required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql}
81 account required ${pam_ldap}/lib/security/pam_ldap.so config=${pam_ldap_mysql}
82 '';
83 }
84 ];
85
86 # FIXME: initial sync
87 # FIXME: backup
88 # FIXME: restart after pam
89 # FIXME: pam access doesn’t work (because of php module)
90 services.mysql = rec {
91 enable = true;
92 package = pkgs.mariadb.overrideAttrs(old: rec {
93 cmakeFlags = old.cmakeFlags ++ [ "-DWITH_AUTHENTICATION_PAM=ON" ];
94 buildInputs = old.buildInputs ++ [ pkgs.pam ];
95 });
96 };
97
a1bb33c4 98 # FIXME: initial sync
dedf591d 99 # FIXME: backup
a1bb33c4
IB
100 services.postgresql = rec {
101 enable = true;
102 package = pkgs.postgresql100.overrideAttrs(old: rec {
103 passthru = old.passthru // { psqlSchema = "11.0"; };
104 name = "postgresql-11.1";
105 src = pkgs.fetchurl {
106 url = "mirror://postgresql/source/v11.1/${name}.tar.bz2";
107 sha256 = "026v0sicsh7avzi45waf8shcbhivyxmi7qgn9fd1x0vl520mx0ch";
108 };
109 });
110 enableTCPIP = true;
111 extraConfig = ''
112 max_connections = 100
113 wal_level = logical
114 shared_buffers = 128MB
115 max_wal_size = 1GB
116 min_wal_size = 80MB
117 log_timezone = 'Europe/Paris'
118 datestyle = 'iso, mdy'
119 timezone = 'Europe/Paris'
120 lc_messages = 'en_US.UTF-8'
121 lc_monetary = 'en_US.UTF-8'
122 lc_numeric = 'en_US.UTF-8'
123 lc_time = 'en_US.UTF-8'
124 default_text_search_config = 'pg_catalog.english'
125 # ssl = on
126 # ssl_cert_file = '/var/lib/acme/eldiron/fullchain.pem'
127 # ssl_key_file = '/var/lib/acme/eldiron/key.pem'
128 '';
129 authentication = ''
130 local all postgres ident
131 local all all md5
132 host all all 178.33.252.96/32 md5
133 host all all 188.165.209.148/32 md5
134 #host all all all pam
135 '';
136 };
137 };
138}