1 { lib, pkgs, config, ... }:
3 secrets = config.myEnv.websites.piedsjaloux.production;
4 cfg = config.myServices.websites.piedsjaloux.production;
5 texlive = pkgs.texlive.combine { inherit (pkgs.texlive) attachfile preprint scheme-small; };
6 ftpRoot = "/var/lib/piedsjaloux_production";
7 phpRoot = "${ftpRoot}/php";
8 webRoot = "${phpRoot}/web";
9 varDir = "${ftpRoot}/var";
10 sessionDir = "${ftpRoot}/sessions";
11 packagePath = "/var/lib/ftp/release.immae.eu/buildbot/Piedsjaloux";
14 options.myServices.websites.piedsjaloux.production.enable = lib.mkEnableOption "enable PiedsJaloux's website in production";
16 config = lib.mkIf cfg.enable {
17 services.webstats.sites = [ { name = "piedsjaloux.fr"; } ];
18 services.phpfpm.pools.piedsjaloux_production = {
19 user = config.services.httpd.Prod.user;
20 group = config.services.httpd.Prod.group;
22 "listen.owner" = config.services.httpd.Prod.user;
23 "listen.group" = config.services.httpd.Prod.group;
24 "php_admin_value[open_basedir]" = builtins.concatStringsSep ":" [
26 config.secrets.fullPaths."websites/piedsjaloux/production"
29 "php_admin_value[session.save_path]" = sessionDir;
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.php74;
41 systemd.services."phpfpm-piedsjaloux_production" = {
42 after = lib.mkAfter ["mysql.service"];
43 wants = ["mysql.service"];
44 path = lib.mkAfter [ pkgs.gnutar pkgs.gzip pkgs.php74 ];
46 script = pkgs.writeScriptBin "piedsjaloux-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,data,miniatures,tmp}
61 ln -sf ${varDir}/{logs,cache,data,miniatures,tmp} var/
62 ln -sf ${config.secrets.fullPaths."websites/piedsjaloux/production"} app/config/parameters.yml
63 ./bin/console --env=${secrets.environment} cache:clear --no-warmup
64 sha256sum ${packagePath}/${branch}.tar.gz > ${ftpRoot}/.tarball_sum
67 "/run/wrappers/bin/sudo -u ${config.services.httpd.Prod.user} ${script}/bin/piedsjaloux-production-pre";
69 script = pkgs.writeScriptBin "piedsjaloux-production-post" ''
70 #! ${pkgs.stdenv.shell}
73 if [ -d php_old ]; then
78 "/run/wrappers/bin/sudo -u ${config.services.httpd.Prod.user} ${script}/bin/piedsjaloux-production-post";
79 serviceConfig.TimeoutStartSec="infinity";
81 services.filesWatcher.phpfpm-piedsjaloux_production = {
83 paths = [ "${packagePath}/${branch}.tar.gz" ];
86 system.activationScripts.piedsjaloux_production = {
89 install -m 0700 -o ${config.services.httpd.Prod.user} -g ${config.services.httpd.Prod.group} -d ${ftpRoot} ${sessionDir}
93 secrets.keys."websites/piedsjaloux/production" = {
94 user = config.services.httpd.Prod.user;
95 group = config.services.httpd.Prod.group;
98 # This file is auto-generated during the composer install
100 database_host: ${secrets.mysql.host}
101 database_port: ${secrets.mysql.port}
102 database_name: ${secrets.mysql.database}
103 database_user: ${secrets.mysql.user}
104 database_password: ${secrets.mysql.password}
105 database_server_version: ${pkgs.mariadb.mysqlVersion}
106 mailer_transport: smtp
107 mailer_host: 127.0.0.1
109 mailer_password: null
110 secret: ${secrets.secret}
111 pdflatex: "${texlive}/bin/pdflatex"
113 binary_path: ${pkgs.imagemagick}/bin
117 services.websites.env.production.vhostConfs.piedsjaloux_production = {
118 certName = "piedsjaloux";
119 certMainHost = "piedsjaloux.fr";
120 hosts = [ "piedsjaloux.fr" "www.piedsjaloux.fr" ];
125 RewriteCond "%{HTTP_HOST}" "!^www.piedsjaloux\.fr$" [NC]
126 RewriteRule ^(.+)$ https://www.piedsjaloux.fr$1 [R=302,L]
128 <FilesMatch "\.php$">
129 SetHandler "proxy:unix:${config.services.phpfpm.pools.piedsjaloux_production.socket}|fcgi://localhost"
132 Use Stats piedsjaloux.fr
134 <Directory ${webRoot}>
135 Options Indexes FollowSymLinks MultiViews Includes