]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - virtual/eldiron.nix
Move httpd service to module
[perso/Immae/Config/Nix.git] / virtual / eldiron.nix
CommitLineData
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 31 ./modules/gitolite.nix
950ca5ee 32 ./modules/gitweb
4d4f13f4 33 ./modules/databases.nix
54307da4 34 ./modules/websites
98584540 35 ./modules/websites/phpfpm
4d4f13f4
IB
36 ];
37 services.myGitolite.enable = true;
38 services.myGitweb.enable = true;
39 services.myDatabases.enable = true;
42429ef0
IB
40 services.myWebsites.production.enable = true;
41 services.myWebsites.integration.enable = true;
4d4f13f4 42
a1bb33c4
IB
43 networking = {
44 firewall = {
45 enable = true;
54307da4 46 allowedTCPPorts = [ 22 9418 ];
a1bb33c4
IB
47 };
48 };
49
50 deployment = {
51 targetEnv = "hetzner";
52 hetzner = {
53 #robotUser = "defined in HETZNER_ROBOT_USER";
54 #robotPass = "defined in HETZNER_ROBOT_PASS";
f8bde3d6 55 mainIPv4 = myconfig.ips.main;
a1bb33c4
IB
56 partitions = ''
57 clearpart --all --initlabel --drives=sda,sdb
58
59 part swap1 --recommended --label=swap1 --fstype=swap --ondisk=sda
60 part swap2 --recommended --label=swap2 --fstype=swap --ondisk=sdb
61
62 part raid.1 --grow --ondisk=sda
63 part raid.2 --grow --ondisk=sdb
64
65 raid / --level=1 --device=md0 --fstype=ext4 --label=root raid.1 raid.2
66 '';
67 };
68 };
69
66b5bbf6
IB
70 environment.systemPackages = let
71 # FIXME: move it to nextcloud
72 occ = pkgs.writeScriptBin "nextcloud-occ" ''
73 #! ${pkgs.stdenv.shell}
74 cd ${mypkgs.nextcloud.webRoot}
75 NEXTCLOUD_CONFIG_DIR="${mypkgs.nextcloud.webRoot}/config" \
76 exec \
98584540
IB
77 ${pkgs.php}/bin/php \
78 -c ${pkgs.php}/etc/php.ini \
66b5bbf6
IB
79 occ $*
80 '';
81 in [
ce6ee3b8 82 pkgs.telnet
beeed847 83 pkgs.htop
ce6ee3b8 84 pkgs.vim
66b5bbf6 85 occ
ce6ee3b8
IB
86 ];
87
3013caf1
IB
88 security.acme.certs."eldiron".extraDomains = {
89 "db-1.immae.eu" = null;
90 "tools.immae.eu" = null;
91 "cloud.immae.eu" = null;
92 "dav.immae.eu" = null;
a1bb33c4
IB
93 };
94
5566d26d
IB
95 services.openssh.extraConfig = ''
96 AuthorizedKeysCommand /etc/ssh/ldap_authorized_keys
97 AuthorizedKeysCommandUser nobody
98 '';
99
beeed847 100 services.ympd = mypkgs.ympd.config // { enable = false; };
a05f8abe 101
98584540
IB
102 services.myPhpfpm = {
103 phpPackage = pkgs.php;
66b5bbf6 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 108 '';
58d1a782
IB
109 extraConfig = ''
110 log_level = notice
111 '';
98584540
IB
112 poolPhpConfigs = {
113 nextcloud = mypkgs.nextcloud.phpFpm.phpConfig;
114 };
58d1a782 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
eb770e14
IB
158 systemd.services.tt-rss = {
159 description = "Tiny Tiny RSS feeds update daemon";
160 serviceConfig = {
161 User = "wwwrun";
162 ExecStart = "${pkgs.php}/bin/php ${mypkgs.ttrss.webRoot}/update.php --daemon";
163 StandardOutput = "syslog";
164 StandardError = "syslog";
165 PermissionsStartOnly = true;
166 };
167
168 wantedBy = [ "multi-user.target" ];
169 requires = ["postgresql.service"];
170 after = ["network.target" "postgresql.service"];
171 };
a1bb33c4
IB
172 };
173}