aboutsummaryrefslogtreecommitdiff
path: root/virtual
diff options
context:
space:
mode:
Diffstat (limited to 'virtual')
-rw-r--r--virtual/connexionswing_master.json14
-rw-r--r--virtual/eldiron.nix17
-rw-r--r--virtual/packages.nix155
3 files changed, 186 insertions, 0 deletions
diff --git a/virtual/connexionswing_master.json b/virtual/connexionswing_master.json
new file mode 100644
index 0000000..30c0c96
--- /dev/null
+++ b/virtual/connexionswing_master.json
@@ -0,0 +1,14 @@
1{
2 "tag": "0c9458f-master",
3 "meta": {
4 "name": "connexionswing_master",
5 "url": "gitolite@git.immae.eu:perso/Immae/Projets/Connexionswing",
6 "branch": "master"
7 },
8 "git": {
9 "url": "gitolite@git.immae.eu:perso/Immae/Projets/Connexionswing",
10 "rev": "0c9458fadbda05e1ffc54956162ee92ad4dd6aef",
11 "sha256": "04blmpfpb6j57m032vpddcn1775bwx537zvv7fi25ip2yg507fjv",
12 "fetchSubmodules": true
13 }
14}
diff --git a/virtual/eldiron.nix b/virtual/eldiron.nix
index fb366b7..56c6afd 100644
--- a/virtual/eldiron.nix
+++ b/virtual/eldiron.nix
@@ -49,6 +49,8 @@
49 extraDomains = { 49 extraDomains = {
50 "db-1.immae.eu" = null; 50 "db-1.immae.eu" = null;
51 "tools.immae.eu" = null; 51 "tools.immae.eu" = null;
52 "connexionswing.immae.eu" = null;
53 "sandetludo.immae.eu" = null;
52 }; 54 };
53 }; 55 };
54 }; 56 };
@@ -62,6 +64,7 @@
62 ''; 64 '';
63 poolConfigs = { 65 poolConfigs = {
64 adminer = mypkgs.adminer.phpFpm.pool; 66 adminer = mypkgs.adminer.phpFpm.pool;
67 connexionswing_dev = mypkgs.connexionswing_dev.phpFpm.pool;
65 www = '' 68 www = ''
66 listen = /var/run/phpfpm/www.sock 69 listen = /var/run/phpfpm/www.sock
67 user = wwwrun 70 user = wwwrun
@@ -77,6 +80,10 @@
77 }; 80 };
78 }; 81 };
79 82
83 system.activationScripts = {
84 connexionswing_dev = mypkgs.connexionswing_dev.activationScript;
85 };
86
80 services.httpd = let 87 services.httpd = let
81 withSSL = domain: { 88 withSSL = domain: {
82 enableSSL = true; 89 enableSSL = true;
@@ -92,6 +99,7 @@
92 # FIXME: http2 99 # FIXME: http2
93 extraModules = pkgs.lib.lists.unique ( 100 extraModules = pkgs.lib.lists.unique (
94 mypkgs.adminer.apache.modules ++ 101 mypkgs.adminer.apache.modules ++
102 mypkgs.connexionswing_dev.apache.modules ++
95 [ 103 [
96 "macro" 104 "macro"
97 "ldap" 105 "ldap"
@@ -141,6 +149,15 @@
141 mypkgs.ympd.apache.vhostConf 149 mypkgs.ympd.apache.vhostConf
142 ]; 150 ];
143 }) 151 })
152 (withSSL "eldiron" // {
153 listen = [ { ip = "*"; port = 443; } ];
154 hostName = "connexionswing.immae.eu";
155 serverAliases = [ "sandetludo.immae.eu" ];
156 documentRoot = mypkgs.connexionswing_dev.webRoot;
157 extraConfig = builtins.concatStringsSep "\n" [
158 mypkgs.connexionswing_dev.apache.vhostConf
159 ];
160 })
144 { # Should go last, default fallback 161 { # Should go last, default fallback
145 listen = [ { ip = "*"; port = 80; } ]; 162 listen = [ { ip = "*"; port = 80; } ];
146 hostName = "redirectSSL"; 163 hostName = "redirectSSL";
diff --git a/virtual/packages.nix b/virtual/packages.nix
index 05b0e88..cd98b79 100644
--- a/virtual/packages.nix
+++ b/virtual/packages.nix
@@ -1,6 +1,159 @@
1with import ../libs.nix; 1with import ../libs.nix;
2with nixpkgs_unstable; 2with nixpkgs_unstable;
3let 3let
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 ${if environment == "dev" then ''
65 <Location />
66 Use LDAPConnect
67 Require ldap-group cn=connexionswing.immae.eu,cn=httpd,ou=services,dc=immae,dc=eu
68 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://connexionswing.com\"></html>"
69 </Location>
70
71 <Directory ${webRoot}>
72 Options Indexes FollowSymLinks MultiViews Includes
73 AllowOverride None
74 Require all granted
75
76 DirectoryIndex app_dev.php
77
78 <IfModule mod_negotiation.c>
79 Options -MultiViews
80 </IfModule>
81
82 <IfModule mod_rewrite.c>
83 RewriteEngine On
84
85 RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
86 RewriteRule ^(.*) - [E=BASE:%1]
87
88 # Maintenance script
89 RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
90 RewriteCond %{SCRIPT_FILENAME} !maintenance.php
91 RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L]
92 ErrorDocument 503 /maintenance.php
93
94 # Sets the HTTP_AUTHORIZATION header removed by Apache
95 RewriteCond %{HTTP:Authorization} .
96 RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
97
98 RewriteCond %{ENV:REDIRECT_STATUS} ^$
99 RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
100
101 # If the requested filename exists, simply serve it.
102 # We only want to let Apache serve files and not directories.
103 RewriteCond %{REQUEST_FILENAME} -f
104 RewriteRule ^ - [L]
105
106 # Rewrite all other queries to the front controller.
107 RewriteRule ^ %{ENV:BASE}/app_dev.php [L]
108 </IfModule>
109
110 </Directory>
111 '' else ""}
112 '';
113 };
114 activationScript = {
115 deps = [ "wrappers" ];
116 text = ''
117 install -m 0755 -o ${apache.user} -g ${apache.group} -d ${varDir} \
118 ${varDir}/medias \
119 ${varDir}/uploads \
120 ${varDir}/var
121 if [ ! -f "${varDir}/currentWebappDir" -o \
122 "${webappDir}" != "$(cat ${varDir}/currentWebappDir 2>/dev/null)" ]; then
123 pushd ${webappDir} > /dev/null
124 $wrapperDir/sudo -u wwwrun ./bin/console --env=${environment} cache:clear --no-warmup
125 popd > /dev/null
126 echo -n "${webappDir}" > ${varDir}/currentWebappDir
127 fi
128 '';
129 };
130 webappDir = pkgs.stdenv.mkDerivation (fetchedGitPrivate ./connexionswing_master.json // rec {
131 # FIXME: can we do better than symlink?
132 # FIXME: imagick optional
133 # FIXME: initial sync
134 buildPhase = ''
135 export GIT_SSL_CAINFO=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
136 export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
137
138 ln -sf ../../../../../${varDir}/{medias,uploads} web/images/
139 ln -sf ${configRoot} app/config/parameters.yml
140 ${if environment == "dev" then "php bin/composer install" else ''
141 SYMFONY_ENV=prod php bin/composer install --no-dev
142 ./bin/console assetic:dump --env=prod --no-debug
143 ''}
144 rm -rf var
145 ln -sf ../../../../../${varDir}/var var
146 '';
147 installPhase = ''
148 cp -a . $out
149 '';
150 buildInputs = [
151 pkgs.php pkgs.git pkgs.cacert
152 ];
153 });
154 webRoot = "${webappDir}/web";
155 };
156
4 adminer = rec { 157 adminer = rec {
5 webRoot = pkgs.stdenv.mkDerivation rec { 158 webRoot = pkgs.stdenv.mkDerivation rec {
6 version = "4.7.0"; 159 version = "4.7.0";
@@ -91,4 +244,6 @@ in
91 { 244 {
92 inherit adminer; 245 inherit adminer;
93 inherit ympd; 246 inherit ympd;
247 connexionswing_dev = connexionswing { environment = "dev"; };
248 connexionswing_prod = connexionswing { environment = "prod"; };
94 } 249 }