1 { pkgs, lib, writeText, fetchedGitPrivate, stdenv, composerEnv, fetchurl, fetchgit, ruby, sass, imagemagick }:
3 ludivinecassal = { config }: rec {
4 environment = config.environment;
5 varDir = "/var/lib/ludivinecassal_${environment}";
7 dest = "webapps/${environment}-ludivinecassal";
12 # This file is auto-generated during the composer install
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
24 secret: ${config.secret}
25 ldap_host: ldap.immae.eu
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}'
36 binary_path: ${imagemagick}/bin
38 sass: ${sass}/bin/sass
39 ruby: ${ruby}/bin/ruby
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
51 echo -n "${webappDir}" > ${varDir}/currentWebappDir
52 sha512sum /var/secrets/webapps/${environment}-ludivinecassal > ${varDir}/currentKey
55 serviceDeps = [ "mysql.service" ];
56 socket = "/var/run/phpfpm/ludivinecassal-${environment}.sock";
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 ''
71 pm.process_idle_timeout = 60
72 env[SYMFONY_DEBUG_MODE] = "yes"
77 pm.min_spare_servers = 1
78 pm.max_spare_servers = 3
84 modules = [ "proxy_fcgi" ];
85 webappName = "ludivine_${environment}";
86 root = "/run/current-system/webapps/${webappName}";
89 SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost"
92 ${if environment == "dev" then ''
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>"
100 Options Indexes FollowSymLinks MultiViews Includes
104 DirectoryIndex app_dev.php
106 <IfModule mod_negotiation.c>
110 <IfModule mod_rewrite.c>
113 RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
114 RewriteRule ^(.*) - [E=BASE:%1]
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
122 # Sets the HTTP_AUTHORIZATION header removed by Apache
123 RewriteCond %{HTTP:Authorization} .
124 RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
126 RewriteCond %{ENV:REDIRECT_STATUS} ^$
127 RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
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
134 # Rewrite all other queries to the front controller.
135 RewriteRule ^ %{ENV:BASE}/app_dev.php [L]
140 Use Stats ludivinecassal.com
143 Options Indexes FollowSymLinks MultiViews Includes
151 deps = [ "wrappers" ];
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
158 webappDir = composerEnv.buildPackage (
159 import ./php-packages.nix { inherit composerEnv fetchurl fetchgit; } //
160 fetchedGitPrivate ./ludivinecassal.json //
162 noDev = (environment == "prod");
164 export SYMFONY_ENV="${environment}"
165 cp app/config/parameters.yml.dist app/config/parameters.yml
166 cat >> app/config/parameters.yml <<EOF
168 binary_path: ${imagemagick}/bin
170 sass: ${sass}/bin/sass
171 ruby: ${ruby}/bin/ruby
173 sed -i -e "/Incenteev..ParameterHandler..ScriptHandler::buildParameters/d" composer.json
175 # /!\ miniatures and data need to be in the same physical dir due to a
176 # bug in leapt.im (searches for data/../miniatures)
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
182 buildInputs = [ sass ];
184 webRoot = "${webappDir}/web";