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