1 { lib, pkgs, config, ... }:
3 secrets = config.myEnv.websites.ludivine.integration;
4 cfg = config.myServices.websites.ludivine.integration;
5 ftpRoot = "/var/lib/ludivine_integration";
6 phpRoot = "${ftpRoot}/php";
7 webRoot = "${phpRoot}/web";
8 varDir = "${ftpRoot}/var";
9 packagePath = "/var/lib/ftp/release.immae.eu/buildbot/Ludivine";
12 options.myServices.websites.ludivine.integration.enable = lib.mkEnableOption "enable Ludivine's website in integration";
14 config = lib.mkIf cfg.enable {
15 services.phpfpm.pools.ludivine_integration = {
16 user = config.services.httpd.Inte.user;
17 group = config.services.httpd.Inte.group;
19 "listen.owner" = config.services.httpd.Inte.user;
20 "listen.group" = config.services.httpd.Inte.group;
21 "php_admin_value[open_basedir]" = builtins.concatStringsSep ":" [
23 config.secrets.fullPaths."websites/ludivine/integration"
26 "php_admin_value[session.save_handler]" = "redis";
27 "php_admin_value[session.save_path]" = "'unix:///run/redis-php-sessions/redis.sock?persistent=1&prefix=Ludivine:Production:'";
28 "php_admin_value[upload_max_filesize]" = "20M";
29 "php_admin_value[post_max_size]" = "20M";
30 #"php_admin_flag[log_errors]" = "on";
32 "pm.max_children" = "5";
33 "pm.process_idle_timeout" = "60";
36 SYMFONY_DEBUG_MODE = "\"yes\"";
38 phpPackage = pkgs.php72.withExtensions({ enabled, all }: enabled ++ [all.redis]);
40 systemd.services."phpfpm-ludivine_integration" = {
41 after = lib.mkAfter ["mysql.service"];
42 wants = ["mysql.service"];
43 path = lib.mkAfter [ pkgs.gnutar pkgs.gzip pkgs.php72 ];
45 script = pkgs.writeScriptBin "ludivine-integration-pre" ''
46 #! ${pkgs.stdenv.shell}
48 [ -f ${packagePath}/${branch}.tar.gz ] || exit 1
51 if ! [ -f .tarball_sum ] || ! sha256sum -c .tarball_sum; then
52 tar -xf ${packagePath}/${branch}.tar.gz --one-top-level=php_new
59 rm -rf var/{logs,cache,data,miniatures,tmp}
60 ln -sf ${varDir}/{logs,cache,data,miniatures,tmp} var/
61 ln -sf ${config.secrets.fullPaths."websites/ludivine/integration"} app/config/parameters.yml
62 SYMFONY_ENV=dev ./bin/console --env=dev cache:clear --no-warmup
63 sha256sum ${packagePath}/${branch}.tar.gz > ${ftpRoot}/.tarball_sum
66 "/run/wrappers/bin/sudo -u ${config.services.httpd.Inte.user} ${script}/bin/ludivine-integration-pre";
68 script = pkgs.writeScriptBin "ludivine-integration-post" ''
69 #! ${pkgs.stdenv.shell}
72 if [ -d php_old ]; then
77 "/run/wrappers/bin/sudo -u ${config.services.httpd.Inte.user} ${script}/bin/ludivine-integration-post";
78 serviceConfig.TimeoutStartSec="infinity";
80 services.filesWatcher.phpfpm-ludivine_integration = {
82 paths = [ "${packagePath}/${branch}.tar.gz" ];
85 system.activationScripts.ludivine_integration = {
88 install -m 0700 -o ${config.services.httpd.Inte.user} -g ${config.services.httpd.Inte.group} -d ${ftpRoot}
92 secrets.keys."websites/ludivine/integration" = {
93 user = config.services.httpd.Inte.user;
94 group = config.services.httpd.Inte.group;
97 # This file is auto-generated during the composer install
99 database_host: ${secrets.mysql.host}
100 database_port: ${secrets.mysql.port}
101 database_name: ${secrets.mysql.database}
102 database_user: ${secrets.mysql.user}
103 database_password: ${secrets.mysql.password}
104 database_server_version: ${config.myServices.databases.mariadb.package.mysqlVersion}
105 mailer_transport: smtp
106 mailer_host: 127.0.0.1
108 mailer_password: null
109 secret: ${secrets.secret}
110 ldap_host: ldap.immae.eu
115 ldap_user_bind: 'uid={username},ou=users,dc=immae,dc=eu'
116 ldap_base_dn: 'dc=immae,dc=eu'
117 ldap_search_dn: '${secrets.ldap.dn}'
118 ldap_search_password: '${secrets.ldap.password}'
119 ldap_search_filter: '${secrets.ldap.filter}'
121 binary_path: ${pkgs.imagemagick}/bin
123 sass: ${pkgs.sass}/bin/sass
124 ruby: ${pkgs.ruby}/bin/ruby
128 services.websites.env.integration.vhostConfs.ludivine_integration = {
129 certName = "integration";
131 hosts = [ "test.lc.immae.dev" ];
135 <FilesMatch "\.php$">
136 SetHandler "proxy:unix:${config.services.phpfpm.pools.ludivine_integration.socket}|fcgi://localhost"
141 Require ldap-group cn=lc.immae.dev,cn=httpd,ou=services,dc=immae,dc=eu
142 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://ludivinecassal.com\"></html>"
145 <Directory ${webRoot}>
146 Options Indexes FollowSymLinks MultiViews Includes
150 DirectoryIndex app_dev.php
152 <IfModule mod_negotiation.c>
156 <IfModule mod_rewrite.c>
159 RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
160 RewriteRule ^(.*) - [E=BASE:%1]
163 RewriteCond %{DOCUMENT_ROOT}/maintenance.php -f
164 RewriteCond %{SCRIPT_FILENAME} !maintenance.php
165 RewriteRule ^.*$ %{ENV:BASE}/maintenance.php [R=503,L]
166 ErrorDocument 503 /maintenance.php
168 # Sets the HTTP_AUTHORIZATION header removed by Apache
169 RewriteCond %{HTTP:Authorization} .
170 RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
172 RewriteCond %{ENV:REDIRECT_STATUS} ^$
173 RewriteRule ^app_dev\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
175 # If the requested filename exists, simply serve it.
176 # We only want to let Apache serve files and not directories.
177 RewriteCond %{REQUEST_FILENAME} -f
180 # Rewrite all other queries to the front controller.
181 RewriteRule ^ %{ENV:BASE}/app_dev.php [L]