diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-01-25 23:15:08 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-01-25 23:15:08 +0100 |
commit | 01f21083a897b86bf148f1d2bb9c8edca4d3786a (patch) | |
tree | 784f04e9b6ef99a49e572c84e4b7ab40b5eb5fde /nixops/modules/websites/ludivine/ludivinecassal.nix | |
parent | bfe3c9c9df0c5112bc8806483292b55ed0f7e02d (diff) | |
download | Nix-01f21083a897b86bf148f1d2bb9c8edca4d3786a.tar.gz Nix-01f21083a897b86bf148f1d2bb9c8edca4d3786a.tar.zst Nix-01f21083a897b86bf148f1d2bb9c8edca4d3786a.zip |
Rename virtual folder to nixops
Fixes https://git.immae.eu/mantisbt/view.php?id=82
Diffstat (limited to 'nixops/modules/websites/ludivine/ludivinecassal.nix')
-rw-r--r-- | nixops/modules/websites/ludivine/ludivinecassal.nix | 166 |
1 files changed, 166 insertions, 0 deletions
diff --git a/nixops/modules/websites/ludivine/ludivinecassal.nix b/nixops/modules/websites/ludivine/ludivinecassal.nix new file mode 100644 index 0000000..eff0bf8 --- /dev/null +++ b/nixops/modules/websites/ludivine/ludivinecassal.nix | |||
@@ -0,0 +1,166 @@ | |||
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 | configRoot = | ||
7 | writeText "parameters.yml" '' | ||
8 | # This file is auto-generated during the composer install | ||
9 | parameters: | ||
10 | database_host: db-1.immae.eu | ||
11 | database_port: null | ||
12 | database_name: ${config.mysql.name} | ||
13 | database_user: ${config.mysql.user} | ||
14 | database_password: ${config.mysql.password} | ||
15 | database_server_version: ${pkgs.mariadb.mysqlVersion} | ||
16 | mailer_transport: smtp | ||
17 | mailer_host: mail.immae.eu | ||
18 | mailer_user: null | ||
19 | mailer_password: null | ||
20 | secret: ${config.secret} | ||
21 | ldap_host: ldap.immae.eu | ||
22 | ldap_port: 636 | ||
23 | ldap_version: 3 | ||
24 | ldap_ssl: true | ||
25 | ldap_tls: false | ||
26 | ldap_user_bind: 'uid={username},ou=users,dc=immae,dc=eu' | ||
27 | ldap_base_dn: 'dc=immae,dc=eu' | ||
28 | ldap_search_dn: '${config.ldap.dn}' | ||
29 | ldap_search_password: '${config.ldap.password}' | ||
30 | ldap_search_filter: '${config.ldap.search}' | ||
31 | leapt_im: | ||
32 | binary_path: ${imagemagick}/bin | ||
33 | assetic: | ||
34 | sass: ${sass}/bin/sass | ||
35 | ruby: ${ruby}/bin/ruby | ||
36 | ''; | ||
37 | phpFpm = rec { | ||
38 | socket = "/var/run/phpfpm/ludivinecassal-${environment}.sock"; | ||
39 | pool = '' | ||
40 | listen = ${socket} | ||
41 | user = ${apache.user} | ||
42 | group = ${apache.group} | ||
43 | listen.owner = ${apache.user} | ||
44 | listen.group = ${apache.group} | ||
45 | php_admin_value[upload_max_filesize] = 20M | ||
46 | php_admin_value[post_max_size] = 20M | ||
47 | ;php_admin_flag[log_errors] = on | ||
48 | php_admin_value[open_basedir] = "${configRoot}:${webappDir}:${varDir}:/tmp" | ||
49 | php_admin_value[session.save_path] = "${varDir}/phpSessions" | ||
50 | ${if environment == "dev" then '' | ||
51 | pm = ondemand | ||
52 | pm.max_children = 5 | ||
53 | pm.process_idle_timeout = 60 | ||
54 | env[SYMFONY_DEBUG_MODE] = "yes" | ||
55 | '' else '' | ||
56 | pm = dynamic | ||
57 | pm.max_children = 20 | ||
58 | pm.start_servers = 2 | ||
59 | pm.min_spare_servers = 1 | ||
60 | pm.max_spare_servers = 3 | ||
61 | ''}''; | ||
62 | }; | ||
63 | apache = { | ||
64 | user = "wwwrun"; | ||
65 | group = "wwwrun"; | ||
66 | modules = [ "proxy_fcgi" ]; | ||
67 | vhostConf = '' | ||
68 | <FilesMatch "\.php$"> | ||
69 | SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" | ||
70 | </FilesMatch> | ||
71 | |||
72 | ${if environment == "dev" then '' | ||
73 | <Location /> | ||
74 | Use LDAPConnect | ||
75 | Require ldap-group cn=ludivine.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu | ||
76 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://ludivinecassal.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 | Use Stats ludivinecassal.com | ||
121 | |||
122 | <Directory ${webRoot}> | ||
123 | Options Indexes FollowSymLinks MultiViews Includes | ||
124 | AllowOverride All | ||
125 | Require all granted | ||
126 | </Directory> | ||
127 | ''} | ||
128 | ''; | ||
129 | }; | ||
130 | activationScript = { | ||
131 | deps = [ "wrappers" ]; | ||
132 | text = '' | ||
133 | install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} | ||
134 | install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir}/tmp | ||
135 | install -m 0750 -o ${apache.user} -g ${apache.group} -d ${varDir}/phpSessions | ||
136 | if [ ! -f "${varDir}/currentWebappDir" -o \ | ||
137 | "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ]; then | ||
138 | pushd ${webappDir} > /dev/null | ||
139 | $wrapperDir/sudo -u wwwrun ./bin/console --env=${environment} cache:clear --no-warmup | ||
140 | popd > /dev/null | ||
141 | echo -n "${webappDir}" > ${varDir}/currentWebappDir | ||
142 | fi | ||
143 | ''; | ||
144 | }; | ||
145 | webappDir = composerEnv.buildPackage ( | ||
146 | import ./php-packages.nix { inherit composerEnv fetchurl fetchgit; } // | ||
147 | fetchedGitPrivate ./ludivinecassal.json // | ||
148 | rec { | ||
149 | noDev = (environment == "prod"); | ||
150 | preInstall = '' | ||
151 | export SYMFONY_ENV="${environment}" | ||
152 | ln -sf ${configRoot} app/config/parameters.yml | ||
153 | sed -i -e "/Incenteev..ParameterHandler..ScriptHandler::buildParameters/d" composer.json | ||
154 | ''; | ||
155 | # /!\ miniatures and data need to be in the same physical dir due to a | ||
156 | # bug in leapt.im (searches for data/../miniatures) | ||
157 | postInstall = '' | ||
158 | rm -rf var/{logs,cache,data,miniatures,tmp} | ||
159 | ln -sf ../../../../../../../${varDir}/{logs,cache,data,miniatures,tmp} var/ | ||
160 | ''; | ||
161 | buildInputs = [ sass ]; | ||
162 | }); | ||
163 | webRoot = "${webappDir}/web"; | ||
164 | }; | ||
165 | in | ||
166 | ludivinecassal | ||