diff options
Diffstat (limited to 'virtual/modules/websites/tellesflorian')
3 files changed, 216 insertions, 0 deletions
diff --git a/virtual/modules/websites/tellesflorian/default.nix b/virtual/modules/websites/tellesflorian/default.nix new file mode 100644 index 0000000..8f8c35a --- /dev/null +++ b/virtual/modules/websites/tellesflorian/default.nix | |||
@@ -0,0 +1,31 @@ | |||
1 | { lib, pkgs, config, mylibs, ... }: | ||
2 | let | ||
3 | adminer = pkgs.callPackage ../commons/adminer.nix {}; | ||
4 | |||
5 | tellesflorian = pkgs.callPackage ./tellesflorian.nix { inherit (mylibs) checkEnv fetchedGitPrivate; }; | ||
6 | tellesflorian_dev = tellesflorian { environment = "dev"; }; | ||
7 | |||
8 | cfg = config.services.myWebsites.TellesFlorian; | ||
9 | in { | ||
10 | options.services.myWebsites.TellesFlorian = { | ||
11 | integration = { | ||
12 | enable = lib.mkEnableOption "enable Florian Telles's website in integration"; | ||
13 | }; | ||
14 | }; | ||
15 | |||
16 | config = lib.mkIf cfg.integration.enable { | ||
17 | security.acme.certs."eldiron".extraDomains."app.tellesflorian.com" = null; | ||
18 | services.myPhpfpm.poolConfigs.tellesflorian_dev = tellesflorian_dev.phpFpm.pool; | ||
19 | system.activationScripts.tellesflorian_dev = tellesflorian_dev.activationScript; | ||
20 | services.myWebsites.integration.modules = adminer.apache.modules ++ tellesflorian_dev.apache.modules; | ||
21 | services.myWebsites.integration.vhostConfs.tellesflorian = { | ||
22 | certName = "eldiron"; | ||
23 | hosts = ["app.tellesflorian.com" ]; | ||
24 | root = tellesflorian_dev.webRoot; | ||
25 | extraConfig = [ | ||
26 | tellesflorian_dev.apache.vhostConf | ||
27 | adminer.apache.vhostConf | ||
28 | ]; | ||
29 | }; | ||
30 | }; | ||
31 | } | ||
diff --git a/virtual/modules/websites/tellesflorian/tellesflorian.json b/virtual/modules/websites/tellesflorian/tellesflorian.json new file mode 100644 index 0000000..81b42af --- /dev/null +++ b/virtual/modules/websites/tellesflorian/tellesflorian.json | |||
@@ -0,0 +1,14 @@ | |||
1 | { | ||
2 | "tag": "1793d5c-master", | ||
3 | "meta": { | ||
4 | "name": "tellesflorian", | ||
5 | "url": "gitolite@git.immae.eu:perso/florian_telles/stabilo", | ||
6 | "branch": "master" | ||
7 | }, | ||
8 | "git": { | ||
9 | "url": "gitolite@git.immae.eu:perso/florian_telles/stabilo", | ||
10 | "rev": "1793d5c7912d1b20ad1df1ac59be9d7f1220e919", | ||
11 | "sha256": "1zhxcrbglbjb6xfr8sfm4m2miabbkkb0a7543va3b5akrn6yk0cb", | ||
12 | "fetchSubmodules": true | ||
13 | } | ||
14 | } | ||
diff --git a/virtual/modules/websites/tellesflorian/tellesflorian.nix b/virtual/modules/websites/tellesflorian/tellesflorian.nix new file mode 100644 index 0000000..b6b9d4e --- /dev/null +++ b/virtual/modules/websites/tellesflorian/tellesflorian.nix | |||
@@ -0,0 +1,171 @@ | |||
1 | { lib, checkEnv, writeText, fetchedGitPrivate, stdenv, php, git, cacert, phpPackages }: | ||
2 | let | ||
3 | tellesflorian = { environment ? "dev" }: rec { | ||
4 | varPrefix = "TELLESFLORIAN"; | ||
5 | varDir = "/var/lib/tellesflorian_${environment}"; | ||
6 | envName= lib.strings.toUpper environment; | ||
7 | configRoot = | ||
8 | # FIXME: spool emails in prod for when immae.eu is down? | ||
9 | assert checkEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_PASSWORD"; | ||
10 | assert checkEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_USER"; | ||
11 | assert checkEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_NAME"; | ||
12 | assert checkEnv "NIXOPS_${varPrefix}_${envName}_SECRET"; | ||
13 | writeText "parameters.yml" '' | ||
14 | # This file is auto-generated during the composer install | ||
15 | parameters: | ||
16 | database_host: db-1.immae.eu | ||
17 | database_port: null | ||
18 | database_name: ${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_NAME"} | ||
19 | database_user: ${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_USER"} | ||
20 | database_password: ${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_MYSQL_PASSWORD"} | ||
21 | mailer_transport: smtp | ||
22 | mailer_host: mail.immae.eu | ||
23 | mailer_user: null | ||
24 | mailer_password: null | ||
25 | secret: ${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_SECRET"} | ||
26 | ''; | ||
27 | phpFpm = rec { | ||
28 | socket = "/var/run/phpfpm/floriantelles-${environment}.sock"; | ||
29 | pool = '' | ||
30 | listen = ${socket} | ||
31 | user = ${apache.user} | ||
32 | group = ${apache.group} | ||
33 | listen.owner = ${apache.user} | ||
34 | listen.group = ${apache.group} | ||
35 | php_admin_value[upload_max_filesize] = 20M | ||
36 | php_admin_value[post_max_size] = 20M | ||
37 | ;php_admin_flag[log_errors] = on | ||
38 | php_admin_value[open_basedir] = "${configRoot}:${webappDir}:${varDir}:/tmp" | ||
39 | php_admin_value[session.save_path] = "${varDir}/phpSessions" | ||
40 | ${if environment == "dev" then '' | ||
41 | pm = ondemand | ||
42 | pm.max_children = 5 | ||
43 | pm.process_idle_timeout = 60 | ||
44 | env[SYMFONY_DEBUG_MODE] = "yes" | ||
45 | '' else '' | ||
46 | pm = dynamic | ||
47 | pm.max_children = 20 | ||
48 | pm.start_servers = 2 | ||
49 | pm.min_spare_servers = 1 | ||
50 | pm.max_spare_servers = 3 | ||
51 | ''}''; | ||
52 | }; | ||
53 | passwords = | ||
54 | assert checkEnv "NIXOPS_${varPrefix}_${envName}_INVITE_PASSWORDS"; | ||
55 | writeText "tellesflorian_passwords" '' | ||
56 | invite:${builtins.getEnv "NIXOPS_${varPrefix}_${envName}_INVITE_PASSWORDS"} | ||
57 | ''; | ||
58 | apache = { | ||
59 | user = "wwwrun"; | ||
60 | group = "wwwrun"; | ||
61 | modules = [ "proxy_fcgi" ]; | ||
62 | vhostConf = '' | ||
63 | <FilesMatch "\.php$"> | ||
64 | SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" | ||
65 | </FilesMatch> | ||
66 | |||
67 | ${if environment == "dev" then '' | ||
68 | <Location /> | ||
69 | AuthBasicProvider file ldap | ||
70 | Use LDAPConnect | ||
71 | Require ldap-group cn=app.tellesflorian.com,cn=httpd,ou=services,dc=immae,dc=eu | ||
72 | |||
73 | AuthUserFile "${passwords}" | ||
74 | Require user "invite" | ||
75 | |||
76 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://tellesflorian.com\"></html>" | ||
77 | </Location> | ||
78 | |||
79 | <Directory ${webRoot}> | ||
80 | Options Indexes FollowSymLinks MultiViews Includes | ||
81 | AllowOverride None | ||
82 | Require all granted | ||
83 | |||
84 | DirectoryIndex app_dev.php | ||
85 | |||
86 | <IfModule mod_negotiation.c> | ||
87 | Options -MultiViews | ||
88 | </IfModule> | ||
89 | |||
90 | <IfModule mod_rewrite.c> | ||
91 | RewriteEngine On | ||
92 | |||
93 | RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ | ||
94 | RewriteRule ^(.*) - [E=BASE:%1] | ||
95 | |||
96 | # Maintenance script | ||
97 | RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f | ||
98 | RewriteCond %{SCRIPT_FILENAME} !maintenance.php | ||
99 | RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L] | ||
100 | ErrorDocument 503 /maintenance.php | ||
101 | |||
102 | # Sets the HTTP_AUTHORIZATION header removed by Apache | ||
103 | RewriteCond %{HTTP:Authorization} . | ||
104 | RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] | ||
105 | |||
106 | RewriteCond %{ENV:REDIRECT_STATUS} ^$ | ||
107 | RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L] | ||
108 | |||
109 | # If the requested filename exists, simply serve it. | ||
110 | # We only want to let Apache serve files and not directories. | ||
111 | RewriteCond %{REQUEST_FILENAME} -f | ||
112 | RewriteRule ^ - [L] | ||
113 | |||
114 | # Rewrite all other queries to the front controller. | ||
115 | RewriteRule ^ %{ENV:BASE}/app_dev.php [L] | ||
116 | </IfModule> | ||
117 | |||
118 | </Directory> | ||
119 | '' else '' | ||
120 | <Directory ${webRoot}> | ||
121 | Options Indexes FollowSymLinks MultiViews Includes | ||
122 | AllowOverride All | ||
123 | Require all granted | ||
124 | </Directory> | ||
125 | ''} | ||
126 | ''; | ||
127 | }; | ||
128 | activationScript = { | ||
129 | deps = [ "wrappers" ]; | ||
130 | text = '' | ||
131 | install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \ | ||
132 | ${varDir}/var | ||
133 | install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions | ||
134 | if [ ! -f "${varDir}/currentWebappDir" -o \ | ||
135 | "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ]; then | ||
136 | pushd ${webappDir} > /dev/null | ||
137 | $wrapperDir/sudo -u wwwrun ./bin/console --env=${environment} cache:clear --no-warmup | ||
138 | popd > /dev/null | ||
139 | echo -n "${webappDir}" > ${varDir}/currentWebappDir | ||
140 | fi | ||
141 | ''; | ||
142 | }; | ||
143 | webappDir = stdenv.mkDerivation (fetchedGitPrivate ./tellesflorian.json // rec { | ||
144 | # FIXME: can we do better than symlink? | ||
145 | # FIXME: initial sync | ||
146 | # FIXME: backup | ||
147 | buildPhase = '' | ||
148 | export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt | ||
149 | export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt | ||
150 | |||
151 | ln -sf ${configRoot} app/config/parameters.yml | ||
152 | sed -i -e "/Incenteev..ParameterHandler..ScriptHandler::buildParameters/d" composer.json | ||
153 | ${if environment == "dev" then '' | ||
154 | composer install | ||
155 | '' else '' | ||
156 | SYMFONY_ENV=prod composer install --no-dev | ||
157 | ''} | ||
158 | rm -rf var | ||
159 | ln -sf ../../../../../${varDir}/var var | ||
160 | ''; | ||
161 | installPhase = '' | ||
162 | cp -a . $out | ||
163 | ''; | ||
164 | buildInputs = [ | ||
165 | php git cacert phpPackages.composer | ||
166 | ]; | ||
167 | }); | ||
168 | webRoot = "${webappDir}/web"; | ||
169 | }; | ||
170 | in | ||
171 | tellesflorian | ||