]>
Commit | Line | Data |
---|---|---|
1 | { pkgs, lib, writeText, fetchedGitPrivate, stdenv, composerEnv, fetchurl, fetchgit, ruby, sass, imagemagick }: | |
2 | let | |
3 | ludivinecassal = { config }: rec { | |
4 | environment = config.environment; | |
5 | varDir = "/var/lib/ludivinecassal_${environment}"; | |
6 | keys = [{ | |
7 | dest = "webapps/${environment}-ludivinecassal"; | |
8 | user = apache.user; | |
9 | group = apache.group; | |
10 | permissions = "0400"; | |
11 | text = '' | |
12 | # This file is auto-generated during the composer install | |
13 | parameters: | |
14 | database_host: ${config.mysql.host} | |
15 | database_port: ${config.mysql.port} | |
16 | database_name: ${config.mysql.name} | |
17 | database_user: ${config.mysql.user} | |
18 | database_password: ${config.mysql.password} | |
19 | database_server_version: ${pkgs.mariadb.mysqlVersion} | |
20 | mailer_transport: smtp | |
21 | mailer_host: 127.0.0.1 | |
22 | mailer_user: null | |
23 | mailer_password: null | |
24 | secret: ${config.secret} | |
25 | ldap_host: ldap.immae.eu | |
26 | ldap_port: 636 | |
27 | ldap_version: 3 | |
28 | ldap_ssl: true | |
29 | ldap_tls: false | |
30 | ldap_user_bind: 'uid={username},ou=users,dc=immae,dc=eu' | |
31 | ldap_base_dn: 'dc=immae,dc=eu' | |
32 | ldap_search_dn: '${config.ldap.dn}' | |
33 | ldap_search_password: '${config.ldap.password}' | |
34 | ldap_search_filter: '${config.ldap.search}' | |
35 | leapt_im: | |
36 | binary_path: ${imagemagick}/bin | |
37 | assetic: | |
38 | sass: ${sass}/bin/sass | |
39 | ruby: ${ruby}/bin/ruby | |
40 | ''; | |
41 | }]; | |
42 | phpFpm = rec { | |
43 | preStart = '' | |
44 | if [ ! -f "${varDir}/currentWebappDir" -o \ | |
45 | ! -f "${varDir}/currentKey" -o \ | |
46 | "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ] \ | |
47 | || ! sha512sum -c --status ${varDir}/currentKey; then | |
48 | pushd ${webappDir} > /dev/null | |
49 | /run/wrappers/bin/sudo -u wwwrun ./bin/console --env=${environment} cache:clear --no-warmup | |
50 | popd > /dev/null | |
51 | echo -n "${webappDir}" > ${varDir}/currentWebappDir | |
52 | sha512sum /var/secrets/webapps/${environment}-ludivinecassal > ${varDir}/currentKey | |
53 | fi | |
54 | ''; | |
55 | serviceDeps = [ "mysql.service" ]; | |
56 | socket = "/var/run/phpfpm/ludivinecassal-${environment}.sock"; | |
57 | pool = '' | |
58 | listen = ${socket} | |
59 | user = ${apache.user} | |
60 | group = ${apache.group} | |
61 | listen.owner = ${apache.user} | |
62 | listen.group = ${apache.group} | |
63 | php_admin_value[upload_max_filesize] = 20M | |
64 | php_admin_value[post_max_size] = 20M | |
65 | ;php_admin_flag[log_errors] = on | |
66 | php_admin_value[open_basedir] = "/var/secrets/webapps/${environment}-ludivinecassal:${webappDir}:${varDir}:/tmp" | |
67 | php_admin_value[session.save_path] = "${varDir}/phpSessions" | |
68 | ${if environment == "dev" then '' | |
69 | pm = ondemand | |
70 | pm.max_children = 5 | |
71 | pm.process_idle_timeout = 60 | |
72 | env[SYMFONY_DEBUG_MODE] = "yes" | |
73 | '' else '' | |
74 | pm = dynamic | |
75 | pm.max_children = 20 | |
76 | pm.start_servers = 2 | |
77 | pm.min_spare_servers = 1 | |
78 | pm.max_spare_servers = 3 | |
79 | ''}''; | |
80 | }; | |
81 | apache = rec { | |
82 | user = "wwwrun"; | |
83 | group = "wwwrun"; | |
84 | modules = [ "proxy_fcgi" ]; | |
85 | webappName = "ludivine_${environment}"; | |
86 | root = "/run/current-system/webapps/${webappName}"; | |
87 | vhostConf = '' | |
88 | <FilesMatch "\.php$"> | |
89 | SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" | |
90 | </FilesMatch> | |
91 | ||
92 | ${if environment == "dev" then '' | |
93 | <Location /> | |
94 | Use LDAPConnect | |
95 | Require ldap-group cn=ludivine.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu | |
96 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://ludivinecassal.com\"></html>" | |
97 | </Location> | |
98 | ||
99 | <Directory ${root}> | |
100 | Options Indexes FollowSymLinks MultiViews Includes | |
101 | AllowOverride None | |
102 | Require all granted | |
103 | ||
104 | DirectoryIndex app_dev.php | |
105 | ||
106 | <IfModule mod_negotiation.c> | |
107 | Options -MultiViews | |
108 | </IfModule> | |
109 | ||
110 | <IfModule mod_rewrite.c> | |
111 | RewriteEngine On | |
112 | ||
113 | RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ | |
114 | RewriteRule ^(.*) - [E=BASE:%1] | |
115 | ||
116 | # Maintenance script | |
117 | RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f | |
118 | RewriteCond %{SCRIPT_FILENAME} !maintenance.php | |
119 | RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L] | |
120 | ErrorDocument 503 /maintenance.php | |
121 | ||
122 | # Sets the HTTP_AUTHORIZATION header removed by Apache | |
123 | RewriteCond %{HTTP:Authorization} . | |
124 | RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] | |
125 | ||
126 | RewriteCond %{ENV:REDIRECT_STATUS} ^$ | |
127 | RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L] | |
128 | ||
129 | # If the requested filename exists, simply serve it. | |
130 | # We only want to let Apache serve files and not directories. | |
131 | RewriteCond %{REQUEST_FILENAME} -f | |
132 | RewriteRule ^ - [L] | |
133 | ||
134 | # Rewrite all other queries to the front controller. | |
135 | RewriteRule ^ %{ENV:BASE}/app_dev.php [L] | |
136 | </IfModule> | |
137 | ||
138 | </Directory> | |
139 | '' else '' | |
140 | Use Stats ludivinecassal.com | |
141 | ||
142 | <Directory ${root}> | |
143 | Options Indexes FollowSymLinks MultiViews Includes | |
144 | AllowOverride All | |
145 | Require all granted | |
146 | </Directory> | |
147 | ''} | |
148 | ''; | |
149 | }; | |
150 | activationScript = { | |
151 | deps = [ "wrappers" ]; | |
152 | text = '' | |
153 | install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} | |
154 | install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir}/tmp | |
155 | install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions | |
156 | ''; | |
157 | }; | |
158 | webappDir = composerEnv.buildPackage ( | |
159 | import ./php-packages.nix { inherit composerEnv fetchurl fetchgit; } // | |
160 | fetchedGitPrivate ./ludivinecassal.json // | |
161 | rec { | |
162 | noDev = (environment == "prod"); | |
163 | preInstall = '' | |
164 | export SYMFONY_ENV="${environment}" | |
165 | cp app/config/parameters.yml.dist app/config/parameters.yml | |
166 | cat >> app/config/parameters.yml <<EOF | |
167 | leapt_im: | |
168 | binary_path: ${imagemagick}/bin | |
169 | assetic: | |
170 | sass: ${sass}/bin/sass | |
171 | ruby: ${ruby}/bin/ruby | |
172 | EOF | |
173 | sed -i -e "/Incenteev..ParameterHandler..ScriptHandler::buildParameters/d" composer.json | |
174 | ''; | |
175 | # /!\ miniatures and data need to be in the same physical dir due to a | |
176 | # bug in leapt.im (searches for data/../miniatures) | |
177 | postInstall = '' | |
178 | rm -rf var/{logs,cache,data,miniatures,tmp} | |
179 | ln -sf ${varDir}/{logs,cache,data,miniatures,tmp} var/ | |
180 | ln -sf /var/secrets/webapps/${environment}-ludivinecassal app/config/parameters.yml | |
181 | ''; | |
182 | buildInputs = [ sass ]; | |
183 | }); | |
184 | webRoot = "${webappDir}/web"; | |
185 | }; | |
186 | in | |
187 | ludivinecassal |