1 { lib, pkgs, config, ... }:
3 secrets = config.myEnv.websites.isabelle.aten_integration;
4 cfg = config.myServices.websites.isabelle.aten_integration;
5 ftpRoot = "/var/lib/isabelle_aten_integration";
6 phpRoot = "${ftpRoot}/php";
7 webRoot = "${phpRoot}/public";
8 varDir = "${ftpRoot}/var";
9 sessionDir = "${ftpRoot}/sessions";
10 packagePath = "/var/lib/ftp/release.immae.eu/buildbot/IsabelleAten";
13 options.myServices.websites.isabelle.aten_integration.enable = lib.mkEnableOption "enable Aten's website in integration";
15 config = lib.mkIf cfg.enable {
16 services.phpfpm.pools.isabelle_aten_integration = {
17 user = config.services.httpd.Inte.user;
18 group = config.services.httpd.Inte.group;
20 "listen.owner" = config.services.httpd.Inte.user;
21 "listen.group" = config.services.httpd.Inte.group;
22 "php_admin_value[open_basedir]" = builtins.concatStringsSep ":" [
24 config.secrets.fullPaths."websites/isabelle/aten_integration"
27 "php_admin_value[session.save_path]" = sessionDir;
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;
40 systemd.services."phpfpm-isabelle_aten_integration" = {
41 after = lib.mkAfter ["postgresql.service"];
42 wants = ["postgresql.service"];
43 path = lib.mkAfter [ pkgs.gnutar pkgs.gzip pkgs.php72 ];
45 script = pkgs.writeScriptBin "isabelle-aten-integration" ''
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/{log,cache}
60 ln -sf ${varDir}/{log,cache} var/
61 SYMFONY_ENV=dev APP_ENV=dev ./bin/console --env=dev cache:clear --no-warmup
62 sha256sum ${packagePath}/${branch}.tar.gz > ${ftpRoot}/.tarball_sum
65 "/run/wrappers/bin/sudo -u ${config.services.httpd.Inte.user} ${script}/bin/isabelle-aten-integration";
67 script = pkgs.writeScriptBin "isabelle-aten-integration-post" ''
68 #! ${pkgs.stdenv.shell}
71 if [ -d php_old ]; then
76 "/run/wrappers/bin/sudo -u ${config.services.httpd.Inte.user} ${script}/bin/isabelle-aten-integration-post";
77 serviceConfig.TimeoutStartSec="infinity";
79 services.filesWatcher.phpfpm-isabelle_aten_integration = {
81 paths = [ "${packagePath}/${branch}.tar.gz" ];
84 system.activationScripts.isabelle_aten_integration = {
87 install -m 0700 -o ${config.services.httpd.Inte.user} -g ${config.services.httpd.Inte.group} -d ${ftpRoot} ${sessionDir}
91 secrets.keys."websites/isabelle/aten_integration" = {
92 user = config.services.httpd.Inte.user;
93 group = config.services.httpd.Inte.group;
97 # https://secure.php.net/manual/fr/function.parse-url.php
98 # vendor/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php#parseDatabaseUrlQuery
99 psql_url = with secrets.postgresql; "pdo-pgsql://${user}:${password}@invalid:${port}/${database}?host=${socket}";
101 SetEnv APP_ENV "${secrets.environment}"
102 SetEnv APP_SECRET "${secrets.secret}"
103 SetEnv DATABASE_URL "${psql_url}"
106 services.websites.env.integration.vhostConfs.isabelle_aten_integration = {
107 certName = "integration";
109 hosts = [ "aten.ic.immae.dev" ];
113 <FilesMatch "\.php$">
114 SetHandler "proxy:unix:${config.services.phpfpm.pools.isabelle_aten_integration.socket}|fcgi://localhost"
117 Include ${config.secrets.fullPaths."websites/isabelle/aten_integration"}
121 Require ldap-group cn=ic.immae.dev,cn=httpd,ou=services,dc=immae,dc=eu
122 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>"
127 Require ldap-group cn=ic.immae.dev,cn=httpd,ou=services,dc=immae,dc=eu
128 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>"
131 <Directory ${webRoot}>
132 Options Indexes FollowSymLinks MultiViews Includes
135 DirectoryIndex index.php
136 FallbackResource /index.php