]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - nixops/modules/websites/connexionswing/connexionswing.nix
Fix secret permissions
[perso/Immae/Config/Nix.git] / nixops / modules / websites / connexionswing / connexionswing.nix
CommitLineData
2abb172b 1{ pkgs, lib, writeText, fetchedGitPrivate, stdenv, composerEnv, phpPackages, fetchurl, fetchgit }:
940f1834 2let
9d90e7e2
IB
3 connexionswing = { config }: rec {
4 environment = config.environment;
940f1834 5 varDir = "/var/lib/connexionswing_${environment}";
a754e9db
IB
6 keys."${environment}-connexionswing" = {
7 destDir = "/run/keys/webapps";
8 user = apache.user;
9 group = apache.group;
85f5ed68 10 permissions = "0400";
a754e9db 11 text = ''
940f1834
IB
12 # This file is auto-generated during the composer install
13 parameters:
7ebcaad5
IB
14 database_host: ${config.mysql.host}
15 database_port: ${config.mysql.port}
9d90e7e2
IB
16 database_name: ${config.mysql.name}
17 database_user: ${config.mysql.user}
18 database_password: ${config.mysql.password}
d78128ec 19 database_server_version: ${pkgs.mariadb.mysqlVersion}
6f75a415
IB
20 mailer_transport: sendmail
21 mailer_host: null
940f1834
IB
22 mailer_user: null
23 mailer_password: null
9d90e7e2 24 subscription_email: ${config.email}
940f1834 25 allow_robots: true
9d90e7e2 26 secret: ${config.secret}
6f75a415
IB
27 ${if environment == "prod" then ''
28 services:
29 swiftmailer.mailer.default.transport:
30 class: Swift_SendmailTransport
31 arguments: ['/run/wrappers/bin/sendmail -bs']
32 '' else ""}
940f1834 33 '';
a754e9db 34 };
940f1834 35 phpFpm = rec {
a0c845b4 36 serviceDeps = [ "mysql.service" "${environment}-connexionswing-key.service" ];
940f1834 37 socket = "/var/run/phpfpm/connexionswing-${environment}.sock";
2abb172b
IB
38 phpConfig = ''
39 extension=${phpPackages.imagick}/lib/php/extensions/imagick.so
40 '';
940f1834
IB
41 pool = ''
42 listen = ${socket}
43 user = ${apache.user}
44 group = ${apache.group}
45 listen.owner = ${apache.user}
46 listen.group = ${apache.group}
47 php_admin_value[upload_max_filesize] = 20M
48 php_admin_value[post_max_size] = 20M
49 ;php_admin_flag[log_errors] = on
a754e9db 50 php_admin_value[open_basedir] = "/run/wrappers/bin/sendmail:/run/keys/webapps/${environment}-connexionswing:${webappDir}:${varDir}:/tmp"
c8e019b6 51 php_admin_value[session.save_path] = "${varDir}/phpSessions"
940f1834
IB
52 ${if environment == "dev" then ''
53 pm = ondemand
54 pm.max_children = 5
55 pm.process_idle_timeout = 60
56 env[SYMFONY_DEBUG_MODE] = "yes"
57 '' else ''
58 pm = dynamic
59 pm.max_children = 20
60 pm.start_servers = 2
61 pm.min_spare_servers = 1
62 pm.max_spare_servers = 3
63 ''}'';
64 };
e5073add 65 apache = rec {
940f1834
IB
66 user = "wwwrun";
67 group = "wwwrun";
68 modules = [ "proxy_fcgi" ];
e5073add
IB
69 webappName = "connexionswing_${environment}";
70 root = "/run/current-system/webapps/${webappName}";
940f1834
IB
71 vhostConf = ''
72 <FilesMatch "\.php$">
73 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
74 </FilesMatch>
75
76 <Directory ${varDir}/medias>
77 Options FollowSymLinks
78 AllowOverride None
79 Require all granted
80 </Directory>
81
82 <Directory ${varDir}/uploads>
83 Options FollowSymLinks
84 AllowOverride None
85 Require all granted
86 </Directory>
87
88 ${if environment == "dev" then ''
89 <Location />
90 Use LDAPConnect
91 Require ldap-group cn=connexionswing.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu
92 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://connexionswing.com\"></html>"
93 </Location>
94
e5073add 95 <Directory ${root}>
940f1834
IB
96 Options Indexes FollowSymLinks MultiViews Includes
97 AllowOverride None
98 Require all granted
99
100 DirectoryIndex app_dev.php
101
102 <IfModule mod_negotiation.c>
103 Options -MultiViews
104 </IfModule>
105
106 <IfModule mod_rewrite.c>
107 RewriteEngine On
108
109 RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
110 RewriteRule ^(.*) - [E=BASE:%1]
111
112 # Maintenance script
113 RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
114 RewriteCond %{SCRIPT_FILENAME} !maintenance.php
115 RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L]
116 ErrorDocument 503 /maintenance.php
117
118 # Sets the HTTP_AUTHORIZATION header removed by Apache
119 RewriteCond %{HTTP:Authorization} .
120 RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
121
122 RewriteCond %{ENV:REDIRECT_STATUS} ^$
123 RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
124
125 # If the requested filename exists, simply serve it.
126 # We only want to let Apache serve files and not directories.
127 RewriteCond %{REQUEST_FILENAME} -f
128 RewriteRule ^ - [L]
129
130 # Rewrite all other queries to the front controller.
131 RewriteRule ^ %{ENV:BASE}/app_dev.php [L]
132 </IfModule>
133
134 </Directory>
e42ba74f 135 '' else ''
527e32ad
IB
136 Use Stats connexionswing.com
137
7da3ceec 138 <Directory ${root}>
e42ba74f
IB
139 Options Indexes FollowSymLinks MultiViews Includes
140 AllowOverride All
141 Require all granted
142 </Directory>
143 ''}
940f1834
IB
144 '';
145 };
146 activationScript = {
147 deps = [ "wrappers" ];
148 text = ''
149 install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \
150 ${varDir}/medias \
151 ${varDir}/uploads \
152 ${varDir}/var
c8e019b6 153 install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions
940f1834
IB
154 if [ ! -f "${varDir}/currentWebappDir" -o \
155 "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ]; then
156 pushd ${webappDir} > /dev/null
157 $wrapperDir/sudo -u wwwrun ./bin/console --env=${environment} cache:clear --no-warmup
158 popd > /dev/null
159 echo -n "${webappDir}" > ${varDir}/currentWebappDir
160 fi
161 '';
162 };
d78128ec
IB
163 webappDir = composerEnv.buildPackage (
164 import ./php-packages.nix { inherit composerEnv fetchurl fetchgit; } //
165 fetchedGitPrivate ./connexionswing.json //
166 rec {
167 noDev = (environment == "prod");
168 preInstall = ''
169 export SYMFONY_ENV="${environment}"
170 '';
171 postInstall = ''
172 cd $out
173 ${if environment == "prod" then "php ./bin/console assetic:dump --env=prod --no-debug" else ""}
174 rm app/config/parameters.yml
a754e9db 175 ln -sf /run/keys/webapps/${environment}-connexionswing app/config/parameters.yml
d78128ec 176 rm -rf var/{logs,cache}
3c8d7f87
IB
177 ln -sf ${varDir}/var/{logs,cache} var/
178 ln -sf ${varDir}/{medias,uploads} web/images/
d78128ec
IB
179 '';
180 });
940f1834
IB
181 webRoot = "${webappDir}/web";
182 };
5c101474 183in
940f1834 184 connexionswing