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