diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-01-01 19:18:08 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-01-01 19:18:08 +0100 |
commit | 940f18341ee8f1e86a18a3488c41b5bbef909cd1 (patch) | |
tree | 77df5726342e3b08757db7c7bd6c4300349308a5 /virtual/packages/connexionswing.nix | |
parent | 66b5bbf6214e8b2f599c394c442638257b149b55 (diff) | |
download | Nix-940f18341ee8f1e86a18a3488c41b5bbef909cd1.tar.gz Nix-940f18341ee8f1e86a18a3488c41b5bbef909cd1.tar.zst Nix-940f18341ee8f1e86a18a3488c41b5bbef909cd1.zip |
Move packages to specific files
Diffstat (limited to 'virtual/packages/connexionswing.nix')
-rw-r--r-- | virtual/packages/connexionswing.nix | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/virtual/packages/connexionswing.nix b/virtual/packages/connexionswing.nix new file mode 100644 index 0000000..a0f5fa6 --- /dev/null +++ b/virtual/packages/connexionswing.nix | |||
@@ -0,0 +1,170 @@ | |||
1 | with import ../../libs.nix; | ||
2 | with nixpkgs_unstable; | ||
3 | let | ||
4 | connexionswing = { environment ? "dev" }: rec { | ||
5 | varDir = "/var/lib/connexionswing_${environment}"; | ||
6 | envName= lib.strings.toUpper environment; | ||
7 | configRoot = | ||
8 | # FIXME: spool emails in prod for when immae.eu is down? | ||
9 | assert checkEnv "NIXOPS_CONNEXIONSWING_${envName}_MYSQL_PASSWORD"; | ||
10 | assert checkEnv "NIXOPS_CONNEXIONSWING_${envName}_MYSQL_USER"; | ||
11 | assert checkEnv "NIXOPS_CONNEXIONSWING_${envName}_MYSQL_NAME"; | ||
12 | assert checkEnv "NIXOPS_CONNEXIONSWING_${envName}_SECRET"; | ||
13 | assert checkEnv "NIXOPS_CONNEXIONSWING_${envName}_EMAIL"; | ||
14 | pkgs.writeText "parameters.yml" '' | ||
15 | # This file is auto-generated during the composer install | ||
16 | parameters: | ||
17 | database_host: db-1.immae.eu | ||
18 | database_port: null | ||
19 | database_name: ${builtins.getEnv "NIXOPS_CONNEXIONSWING_${envName}_MYSQL_NAME"} | ||
20 | database_user: ${builtins.getEnv "NIXOPS_CONNEXIONSWING_${envName}_MYSQL_USER"} | ||
21 | database_password: ${builtins.getEnv "NIXOPS_CONNEXIONSWING_${envName}_MYSQL_PASSWORD"} | ||
22 | mailer_transport: smtp | ||
23 | mailer_host: mail.immae.eu | ||
24 | mailer_user: null | ||
25 | mailer_password: null | ||
26 | subscription_email: ${builtins.getEnv "NIXOPS_CONNEXIONSWING_${envName}_EMAIL"} | ||
27 | allow_robots: true | ||
28 | secret: ${builtins.getEnv "NIXOPS_CONNEXIONSWING_${envName}_SECRET"} | ||
29 | ''; | ||
30 | phpFpm = rec { | ||
31 | socket = "/var/run/phpfpm/connexionswing-${environment}.sock"; | ||
32 | pool = '' | ||
33 | listen = ${socket} | ||
34 | user = ${apache.user} | ||
35 | group = ${apache.group} | ||
36 | listen.owner = ${apache.user} | ||
37 | listen.group = ${apache.group} | ||
38 | php_admin_value[upload_max_filesize] = 20M | ||
39 | php_admin_value[post_max_size] = 20M | ||
40 | ;php_admin_flag[log_errors] = on | ||
41 | php_admin_value[open_basedir] = "${configRoot}:${webappDir}:${varDir}:/tmp" | ||
42 | ${if environment == "dev" then '' | ||
43 | pm = ondemand | ||
44 | pm.max_children = 5 | ||
45 | pm.process_idle_timeout = 60 | ||
46 | env[SYMFONY_DEBUG_MODE] = "yes" | ||
47 | '' else '' | ||
48 | pm = dynamic | ||
49 | pm.max_children = 20 | ||
50 | pm.start_servers = 2 | ||
51 | pm.min_spare_servers = 1 | ||
52 | pm.max_spare_servers = 3 | ||
53 | ''}''; | ||
54 | }; | ||
55 | apache = { | ||
56 | user = "wwwrun"; | ||
57 | group = "wwwrun"; | ||
58 | modules = [ "proxy_fcgi" ]; | ||
59 | vhostConf = '' | ||
60 | <FilesMatch "\.php$"> | ||
61 | SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" | ||
62 | </FilesMatch> | ||
63 | |||
64 | <Directory ${varDir}/medias> | ||
65 | Options FollowSymLinks | ||
66 | AllowOverride None | ||
67 | Require all granted | ||
68 | </Directory> | ||
69 | |||
70 | <Directory ${varDir}/uploads> | ||
71 | Options FollowSymLinks | ||
72 | AllowOverride None | ||
73 | Require all granted | ||
74 | </Directory> | ||
75 | |||
76 | ${if environment == "dev" then '' | ||
77 | <Location /> | ||
78 | Use LDAPConnect | ||
79 | Require ldap-group cn=connexionswing.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu | ||
80 | ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://connexionswing.com\"></html>" | ||
81 | </Location> | ||
82 | |||
83 | <Directory ${webRoot}> | ||
84 | Options Indexes FollowSymLinks MultiViews Includes | ||
85 | AllowOverride None | ||
86 | Require all granted | ||
87 | |||
88 | DirectoryIndex app_dev.php | ||
89 | |||
90 | <IfModule mod_negotiation.c> | ||
91 | Options -MultiViews | ||
92 | </IfModule> | ||
93 | |||
94 | <IfModule mod_rewrite.c> | ||
95 | RewriteEngine On | ||
96 | |||
97 | RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ | ||
98 | RewriteRule ^(.*) - [E=BASE:%1] | ||
99 | |||
100 | # Maintenance script | ||
101 | RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f | ||
102 | RewriteCond %{SCRIPT_FILENAME} !maintenance.php | ||
103 | RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L] | ||
104 | ErrorDocument 503 /maintenance.php | ||
105 | |||
106 | # Sets the HTTP_AUTHORIZATION header removed by Apache | ||
107 | RewriteCond %{HTTP:Authorization} . | ||
108 | RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] | ||
109 | |||
110 | RewriteCond %{ENV:REDIRECT_STATUS} ^$ | ||
111 | RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L] | ||
112 | |||
113 | # If the requested filename exists, simply serve it. | ||
114 | # We only want to let Apache serve files and not directories. | ||
115 | RewriteCond %{REQUEST_FILENAME} -f | ||
116 | RewriteRule ^ - [L] | ||
117 | |||
118 | # Rewrite all other queries to the front controller. | ||
119 | RewriteRule ^ %{ENV:BASE}/app_dev.php [L] | ||
120 | </IfModule> | ||
121 | |||
122 | </Directory> | ||
123 | '' else ""} | ||
124 | ''; | ||
125 | }; | ||
126 | activationScript = { | ||
127 | deps = [ "wrappers" ]; | ||
128 | text = '' | ||
129 | install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \ | ||
130 | ${varDir}/medias \ | ||
131 | ${varDir}/uploads \ | ||
132 | ${varDir}/var | ||
133 | if [ ! -f "${varDir}/currentWebappDir" -o \ | ||
134 | "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ]; then | ||
135 | pushd ${webappDir} > /dev/null | ||
136 | $wrapperDir/sudo -u wwwrun ./bin/console --env=${environment} cache:clear --no-warmup | ||
137 | popd > /dev/null | ||
138 | echo -n "${webappDir}" > ${varDir}/currentWebappDir | ||
139 | fi | ||
140 | ''; | ||
141 | }; | ||
142 | webappDir = pkgs.stdenv.mkDerivation (fetchedGitPrivate ./connexionswing_master.json // rec { | ||
143 | # FIXME: can we do better than symlink? | ||
144 | # FIXME: imagick optional | ||
145 | # FIXME: initial sync | ||
146 | # FIXME: backup | ||
147 | buildPhase = '' | ||
148 | export GIT_SSL_CAINFO=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt | ||
149 | export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt | ||
150 | |||
151 | ln -sf ../../../../../${varDir}/{medias,uploads} web/images/ | ||
152 | ln -sf ${configRoot} app/config/parameters.yml | ||
153 | ${if environment == "dev" then "php bin/composer install" else '' | ||
154 | SYMFONY_ENV=prod php bin/composer install --no-dev | ||
155 | ./bin/console assetic:dump --env=prod --no-debug | ||
156 | ''} | ||
157 | rm -rf var | ||
158 | ln -sf ../../../../../${varDir}/var var | ||
159 | ''; | ||
160 | installPhase = '' | ||
161 | cp -a . $out | ||
162 | ''; | ||
163 | buildInputs = [ | ||
164 | pkgs.php pkgs.git pkgs.cacert | ||
165 | ]; | ||
166 | }); | ||
167 | webRoot = "${webappDir}/web"; | ||
168 | }; | ||
169 | in | ||
170 | connexionswing | ||