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