]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - virtual/eldiron.nix
Move some more configuration for websites
[perso/Immae/Config/Nix.git] / virtual / eldiron.nix
CommitLineData
a1bb33c4
IB
1{
2 network = {
3 description = "Immae's network";
4 enableRollback = true;
5 };
6
f8bde3d6 7 eldiron = { config, pkgs, mylibs, myconfig, ... }:
4d4f13f4 8 with mylibs;
5c101474 9 let
712ccefd 10 mypkgs = pkgs.callPackage ./packages.nix {
ad915416 11 inherit checkEnv fetchedGit fetchedGithub;
5c101474 12 };
ab5d04b8
IB
13 in
14 {
4d4f13f4
IB
15 _module.args = {
16 mylibs = import ../libs.nix;
f8bde3d6
IB
17 myconfig = {
18 ips = {
19 main = "176.9.151.89";
20 production = "176.9.151.154";
21 integration = "176.9.151.155";
22 };
23 };
4d4f13f4
IB
24 };
25
26 imports = [
3013caf1 27 ./modules/certificates.nix
4d4f13f4
IB
28 ./modules/gitolite.nix
29 ./modules/gitweb.nix
30 ./modules/databases.nix
54307da4 31 ./modules/websites
4d4f13f4
IB
32 ];
33 services.myGitolite.enable = true;
34 services.myGitweb.enable = true;
35 services.myDatabases.enable = true;
42429ef0
IB
36 services.myWebsites.production.enable = true;
37 services.myWebsites.integration.enable = true;
4d4f13f4 38
a1bb33c4
IB
39 networking = {
40 firewall = {
41 enable = true;
54307da4 42 allowedTCPPorts = [ 22 9418 ];
a1bb33c4
IB
43 };
44 };
45
46 deployment = {
47 targetEnv = "hetzner";
48 hetzner = {
49 #robotUser = "defined in HETZNER_ROBOT_USER";
50 #robotPass = "defined in HETZNER_ROBOT_PASS";
f8bde3d6 51 mainIPv4 = myconfig.ips.main;
a1bb33c4
IB
52 partitions = ''
53 clearpart --all --initlabel --drives=sda,sdb
54
55 part swap1 --recommended --label=swap1 --fstype=swap --ondisk=sda
56 part swap2 --recommended --label=swap2 --fstype=swap --ondisk=sdb
57
58 part raid.1 --grow --ondisk=sda
59 part raid.2 --grow --ondisk=sdb
60
61 raid / --level=1 --device=md0 --fstype=ext4 --label=root raid.1 raid.2
62 '';
63 };
64 };
65
66b5bbf6
IB
66 environment.systemPackages = let
67 # FIXME: move it to nextcloud
68 occ = pkgs.writeScriptBin "nextcloud-occ" ''
69 #! ${pkgs.stdenv.shell}
70 cd ${mypkgs.nextcloud.webRoot}
71 NEXTCLOUD_CONFIG_DIR="${mypkgs.nextcloud.webRoot}/config" \
72 exec \
73 ${config.services.phpfpm.phpPackage}/bin/php \
74 -c ${config.services.phpfpm.phpPackage}/etc/php.ini \
75 occ $*
76 '';
77 in [
ce6ee3b8 78 pkgs.telnet
beeed847 79 pkgs.htop
ce6ee3b8 80 pkgs.vim
66b5bbf6 81 occ
ce6ee3b8
IB
82 ];
83
3013caf1
IB
84 security.acme.certs."eldiron".extraDomains = {
85 "db-1.immae.eu" = null;
86 "tools.immae.eu" = null;
87 "cloud.immae.eu" = null;
88 "dav.immae.eu" = null;
a1bb33c4
IB
89 };
90
5566d26d
IB
91 services.openssh.extraConfig = ''
92 AuthorizedKeysCommand /etc/ssh/ldap_authorized_keys
93 AuthorizedKeysCommandUser nobody
94 '';
95
beeed847 96 services.ympd = mypkgs.ympd.config // { enable = false; };
a05f8abe 97
58d1a782 98 services.phpfpm = {
beeed847 99 # FIXME: move session files to separate dirs
66b5bbf6
IB
100 # /!\ phppackage is used in nextcloud configuation
101 phpOptions = ''
c8e019b6
IB
102 session.save_path = "/var/lib/php/sessions"
103 session.gc_maxlifetime = 60*60*24*15
104 session.cache_expire = 60*24*30
66b5bbf6
IB
105 ; For nextcloud
106 extension=${pkgs.phpPackages.redis}/lib/php/extensions/redis.so
107 ; For nextcloud
108 extension=${pkgs.phpPackages.apcu}/lib/php/extensions/apcu.so
ec9ff2b8
IB
109 ; For nextcloud
110 zend_extension=${pkgs.php}/lib/php/extensions/opcache.so
66b5bbf6 111 '';
58d1a782
IB
112 extraConfig = ''
113 log_level = notice
114 '';
115 poolConfigs = {
27e22b76 116 adminer = mypkgs.adminer.phpFpm.pool;
66b5bbf6 117 nextcloud = mypkgs.nextcloud.phpFpm.pool;
50d8fa14 118 mantisbt = mypkgs.mantisbt.phpFpm.pool;
eb770e14 119 ttrss = mypkgs.ttrss.phpFpm.pool;
d252d718 120 roundcubemail = mypkgs.roundcubemail.phpFpm.pool;
d9998b44 121 davical = mypkgs.davical.phpFpm.pool;
58d1a782
IB
122 };
123 };
124
65fe7543 125 system.activationScripts = {
66b5bbf6 126 nextcloud = mypkgs.nextcloud.activationScript;
eb770e14 127 ttrss = mypkgs.ttrss.activationScript;
d252d718 128 roundcubemail = mypkgs.roundcubemail.activationScript;
5dd28b43
IB
129 httpd = ''
130 install -d -m 0755 /var/lib/acme/acme-challenge
c8e019b6
IB
131 install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions
132 install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions/adminer
133 install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions/mantisbt
1635a4ae 134 install -d -m 0750 -o wwwrun -g wwwrun /var/lib/php/sessions/davical
5dd28b43 135 '';
5566d26d
IB
136 };
137
138 environment.etc."ssh/ldap_authorized_keys" = let
139 ldap_authorized_keys =
5c101474
IB
140 assert checkEnv "NIXOPS_SSHD_LDAP_PASSWORD";
141 wrap {
5566d26d
IB
142 name = "ldap_authorized_keys";
143 file = ./ldap_authorized_keys.sh;
144 vars = {
145 LDAP_PASS = builtins.getEnv "NIXOPS_SSHD_LDAP_PASSWORD";
146 GITOLITE_SHELL = "${pkgs.gitolite}/bin/gitolite-shell";
147 ECHO = "${pkgs.coreutils}/bin/echo";
148 };
149 paths = [ pkgs.openldap pkgs.stdenv.shellPackage pkgs.gnugrep pkgs.gnused pkgs.coreutils ];
150 };
151 in {
152 enable = true;
153 mode = "0755";
154 user = "root";
155 source = ldap_authorized_keys;
65fe7543
IB
156 };
157
7611e4e2
IB
158 services.gitDaemon = {
159 enable = true;
160 user = "gitolite";
161 group = "gitolite";
162 basePath = "${mypkgs.git.web.varDir}/repositories";
163 };
164
beeed847 165 # FIXME: logrotate
58d1a782 166 services.httpd = let
b7cd7e4b 167 withConf = domain: {
58d1a782 168 enableSSL = true;
5dd28b43 169 sslServerCert = "/var/lib/acme/${domain}/cert.pem";
58d1a782
IB
170 sslServerKey = "/var/lib/acme/${domain}/key.pem";
171 sslServerChain = "/var/lib/acme/${domain}/fullchain.pem";
b7cd7e4b 172 logFormat = "combinedVhost";
f8bde3d6
IB
173 listen = [
174 { ip = "176.9.151.89"; port = 443; }
175 ];
58d1a782 176 };
42429ef0 177 apacheConfig = config.services.myWebsites.apacheConfig;
58d1a782 178 in rec {
a1bb33c4 179 enable = true;
58d1a782
IB
180 logPerVirtualHost = true;
181 multiProcessingModule = "worker";
182 adminAddr = "httpd@immae.eu";
b7cd7e4b 183 logFormat = "combinedVhost";
25fd1d16
IB
184 extraModules = pkgs.lib.lists.unique (
185 mypkgs.adminer.apache.modules ++
66b5bbf6 186 mypkgs.nextcloud.apache.modules ++
5f3e023d 187 mypkgs.ympd.apache.modules ++
cf80b4f2 188 mypkgs.git.web.apache.modules ++
50d8fa14 189 mypkgs.mantisbt.apache.modules ++
eb770e14 190 mypkgs.ttrss.apache.modules ++
d252d718 191 mypkgs.roundcubemail.apache.modules ++
42429ef0 192 pkgs.lib.lists.flatten (pkgs.lib.attrsets.mapAttrsToList (n: v: v.modules or []) apacheConfig));
94818b75 193 extraConfig = builtins.concatStringsSep "\n"
42429ef0 194 (builtins.filter (x: x != null) (pkgs.lib.attrsets.mapAttrsToList (n: v: v.extraConfig or null) apacheConfig));
58d1a782 195 virtualHosts = [
b7cd7e4b 196 (withConf "eldiron" // {
58d1a782 197 hostName = "eldiron.immae.eu";
1d4ccb2c
IB
198 documentRoot = ./www;
199 extraConfig = ''
200 DirectoryIndex index.htm
201 '';
58d1a782 202 })
b7cd7e4b 203 (withConf "eldiron" // {
58d1a782
IB
204 hostName = "db-1.immae.eu";
205 documentRoot = null;
27e22b76 206 extraConfig = builtins.concatStringsSep "\n" [
1bb2ff2c 207 mypkgs.adminer.apache.vhostConf
27e22b76 208 ];
58d1a782 209 })
b7cd7e4b 210 (withConf "eldiron" // {
e379fd29
IB
211 hostName = "tools.immae.eu";
212 documentRoot = null;
213 extraConfig = builtins.concatStringsSep "\n" [
1bb2ff2c 214 mypkgs.adminer.apache.vhostConf
a05f8abe 215 mypkgs.ympd.apache.vhostConf
eb770e14 216 mypkgs.ttrss.apache.vhostConf
d252d718 217 mypkgs.roundcubemail.apache.vhostConf
43b726ed
IB
218 ];
219 })
220 (withConf "eldiron" // {
221 hostName = "dav.immae.eu";
222 documentRoot = null;
223 extraConfig = builtins.concatStringsSep "\n" [
1635a4ae 224 mypkgs.infcloud.apache.vhostConf
d9998b44 225 mypkgs.davical.apache.vhostConf
e379fd29
IB
226 ];
227 })
b7cd7e4b 228 (withConf "eldiron" // {
66b5bbf6
IB
229 hostName = "cloud.immae.eu";
230 documentRoot = mypkgs.nextcloud.webRoot;
231 extraConfig = builtins.concatStringsSep "\n" [
232 mypkgs.nextcloud.apache.vhostConf
233 ];
234 })
b7cd7e4b 235 (withConf "eldiron" // {
cf80b4f2
IB
236 hostName = "git.immae.eu";
237 documentRoot = mypkgs.git.web.webRoot;
238 extraConfig = builtins.concatStringsSep "\n" [
239 mypkgs.git.web.apache.vhostConf
50d8fa14 240 mypkgs.mantisbt.apache.vhostConf
cf80b4f2
IB
241 ] + ''
242 RewriteEngine on
243 RewriteCond %{REQUEST_URI} ^/releases
244 RewriteRule /releases(.*) https://release.immae.eu$1 [P,L]
245 '';
246 })
58d1a782
IB
247 { # Should go last, default fallback
248 listen = [ { ip = "*"; port = 80; } ];
249 hostName = "redirectSSL";
250 serverAliases = [ "*" ];
251 enableSSL = false;
b7cd7e4b 252 logFormat = "combinedVhost";
58d1a782
IB
253 documentRoot = "/var/lib/acme/acme-challenge";
254 extraConfig = ''
255 RewriteEngine on
256 RewriteCond "%{REQUEST_URI}" "!^/\.well-known"
257 RewriteRule ^(.+) https://%{HTTP_HOST}$1 [R=301]
258 # To redirect in specific "VirtualHost *:80", do
259 # RedirectMatch 301 ^/((?!\.well-known.*$).*)$ https://host/$1
260 # rather than rewrite
261 '';
262 }
43b726ed 263 ];
58d1a782
IB
264 };
265
eb770e14
IB
266 systemd.services.tt-rss = {
267 description = "Tiny Tiny RSS feeds update daemon";
268 serviceConfig = {
269 User = "wwwrun";
270 ExecStart = "${pkgs.php}/bin/php ${mypkgs.ttrss.webRoot}/update.php --daemon";
271 StandardOutput = "syslog";
272 StandardError = "syslog";
273 PermissionsStartOnly = true;
274 };
275
276 wantedBy = [ "multi-user.target" ];
277 requires = ["postgresql.service"];
278 after = ["network.target" "postgresql.service"];
279 };
a1bb33c4
IB
280 };
281}