1 { lib, pkgs, config, ... }:
3 secrets = config.myEnv.websites.connexionswing.production;
4 cfg = config.myServices.websites.connexionswing.production;
5 ftpRoot = "/var/lib/connexionswing_production";
6 phpRoot = "${ftpRoot}/php";
7 webRoot = "${phpRoot}/web";
8 varDir = "${ftpRoot}/var";
9 packagePath = "/var/lib/ftp/release.immae.eu/buildbot/Connexionswing";
12 options.myServices.websites.connexionswing.production.enable = lib.mkEnableOption "enable Connexionswing's website in production";
14 config = lib.mkIf cfg.enable {
15 services.webstats.sites = [ { name = "connexionswing.com"; } ];
16 services.phpfpm.pools.connexionswing_production = {
17 user = config.services.httpd.Prod.user;
18 group = config.services.httpd.Prod.group;
20 "listen.owner" = config.services.httpd.Prod.user;
21 "listen.group" = config.services.httpd.Prod.group;
22 "php_admin_value[open_basedir]" = builtins.concatStringsSep ":" [
24 config.secrets.fullPaths."websites/connexionswing/production"
25 "/run/wrappers/bin/sendmail"
28 "php_admin_value[session.save_handler]" = "redis";
29 "php_admin_value[session.save_path]" = "'unix:///run/redis-php-sessions/redis.sock?persistent=1&prefix=Connexionswing:Production:'";
30 "php_admin_value[upload_max_filesize]" = "20M";
31 "php_admin_value[post_max_size]" = "20M";
32 #"php_admin_flag[log_errors]" = "on";
34 "pm.max_children" = "20";
35 "pm.start_servers" = "2";
36 "pm.min_spare_servers" = "1";
37 "pm.max_spare_servers" = "3";
39 phpPackage = pkgs.php72.withExtensions ({ enabled, all }: enabled ++ [all.redis]);
41 systemd.services."phpfpm-connexionswing_production" = {
42 after = lib.mkAfter ["mysql.service"];
43 wants = ["mysql.service"];
44 path = lib.mkAfter [ pkgs.gnutar pkgs.gzip pkgs.php72 ];
46 script = pkgs.writeScriptBin "connexionswing-production-pre" ''
47 #! ${pkgs.stdenv.shell}
49 [ -f ${packagePath}/${branch}.tar.gz ] || exit 1
52 if ! [ -f .tarball_sum ] || ! sha256sum -c .tarball_sum; then
53 tar -xf ${packagePath}/${branch}.tar.gz --one-top-level=php_new
60 rm -rf var/{logs,cache}
61 ln -sf ${varDir}/var/{logs,cache} var/
62 ln -sf ${varDir}/{medias,uploads} web/images/
63 ln -sf ${config.secrets.fullPaths."websites/connexionswing/production"} app/config/parameters.yml
64 SYMFONY_ENV=${secrets.environment} ./bin/console --env=${secrets.environment} cache:clear --no-warmup
65 sha256sum ${packagePath}/${branch}.tar.gz > ${ftpRoot}/.tarball_sum
68 "/run/wrappers/bin/sudo -u ${config.services.httpd.Prod.user} ${script}/bin/connexionswing-production-pre";
70 script = pkgs.writeScriptBin "connexionswing-production-post" ''
71 #! ${pkgs.stdenv.shell}
74 if [ -d php_old ]; then
79 "/run/wrappers/bin/sudo -u ${config.services.httpd.Prod.user} ${script}/bin/connexionswing-production-post";
80 serviceConfig.TimeoutStartSec="infinity";
82 services.filesWatcher.phpfpm-connexionswing_production = {
84 paths = [ "${packagePath}/${branch}.tar.gz" ];
87 system.activationScripts.connexionswing_production = {
90 install -m 0700 -o ${config.services.httpd.Prod.user} -g ${config.services.httpd.Prod.group} -d ${ftpRoot}
94 secrets.keys."websites/connexionswing/production" = {
95 user = config.services.httpd.Prod.user;
96 group = config.services.httpd.Prod.group;
99 # This file is auto-generated during the composer install
101 database_host: ${secrets.mysql.host}
102 database_port: ${secrets.mysql.port}
103 database_name: ${secrets.mysql.database}
104 database_user: ${secrets.mysql.user}
105 database_password: ${secrets.mysql.password}
106 database_server_version: ${config.myServices.databases.mariadb.package.mysqlVersion}
107 mailer_transport: sendmail
110 mailer_password: null
111 subscription_email: ${secrets.email}
113 secret: ${secrets.secret}
115 swiftmailer.mailer.default.transport:
116 class: Swift_SendmailTransport
117 arguments: ['/run/wrappers/bin/sendmail -bs']
121 services.websites.env.production.vhostConfs.connexionswing_production = {
122 certName = "connexionswing";
123 certMainHost = "connexionswing.com";
124 hosts = ["connexionswing.com" "sandetludo.com" "www.connexionswing.com" "www.sandetludo.com" ];
128 <FilesMatch "\.php$">
129 SetHandler "proxy:unix:${config.services.phpfpm.pools.connexionswing_production.socket}|fcgi://localhost"
132 <Directory ${varDir}/medias>
133 Options FollowSymLinks
138 <Directory ${varDir}/uploads>
139 Options FollowSymLinks
144 Use Stats connexionswing.com
146 <Directory ${webRoot}>
147 Options Indexes FollowSymLinks MultiViews Includes