{ lib, pkgs, config, ... }:
let
secrets = config.myEnv.websites.isabelle.aten_production;
app = pkgs.callPackage ./aten_app {
composerEnv = pkgs.composerEnv.override { php = pkgs.php72; };
environment = secrets.environment;
varDir = "/var/lib/isabelle_aten_production";
};
cfg = config.myServices.websites.isabelle.aten_production;
pcfg = config.services.phpApplication;
in {
options.myServices.websites.isabelle.aten_production.enable = lib.mkEnableOption "enable Aten's website in production";
config = lib.mkIf cfg.enable {
services.duplyBackup.profiles.isabelle_aten_production.rootDir = app.varDir;
services.duplyBackup.profiles.isabelle_aten_production.remotes = ["eriomem" "ovh"];
services.webstats.sites = [ { name = "aten.pro"; } ];
services.phpApplication.apps.isabelle_aten_production = {
websiteEnv = "production";
httpdUser = config.services.httpd.Prod.user;
httpdGroup = config.services.httpd.Prod.group;
httpdWatchFiles = [
config.secrets.fullPaths."websites/isabelle/aten_production"
];
inherit (app) webRoot varDir;
inherit app;
serviceDeps = [ "postgresql.service" ];
preStartActions = [
"APP_ENV=${app.environment} ./bin/console --env=${app.environment} cache:clear --no-warmup"
];
phpOpenbasedir = [ "/tmp" ];
phpPool = {
"php_admin_value[upload_max_filesize]" = "20M";
"php_admin_value[post_max_size]" = "20M";
#"php_admin_flag[log_errors]" = "on";
"pm" = "dynamic";
"pm.max_children" = "20";
"pm.start_servers" = "2";
"pm.min_spare_servers" = "1";
"pm.max_spare_servers" = "3";
};
phpPackage = pkgs.php72;
};
secrets.keys."websites/isabelle/aten_production" = {
user = config.services.httpd.Prod.user;
group = config.services.httpd.Prod.group;
permissions = "0400";
text = let
# cf:
# https://secure.php.net/manual/fr/function.parse-url.php
# vendor/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php#parseDatabaseUrlQuery
psql_url = with secrets.postgresql; "pdo-pgsql://${user}:${password}@invalid:${port}/${database}?host=${socket}";
in ''
SetEnv APP_ENV "${app.environment}"
SetEnv APP_SECRET "${secrets.secret}"
SetEnv DATABASE_URL "${psql_url}"
'';
};
services.websites.env.production.vhostConfs.isabelle_aten_production = {
certName = "isabelle";
certMainHost = "aten.pro";
hosts = [ "aten.pro" "www.aten.pro" ];
root = app.webRoot;
extraConfig = [
''
SetHandler "proxy:unix:${pcfg.phpListenPaths.isabelle_aten_production}|fcgi://localhost"
Include ${config.secrets.fullPaths."websites/isabelle/aten_production"}
Use Stats aten.pro
Use LDAPConnect
Require ldap-group cn=aten.pro,cn=httpd,ou=services,dc=immae,dc=eu
ErrorDocument 401 ""
Options Indexes FollowSymLinks MultiViews Includes
AllowOverride All
Require all granted
DirectoryIndex index.php
FallbackResource /index.php
''
];
};
};
}