X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=modules%2Fprivate%2Fwebsites%2Faten%2Fproduction.nix;h=1f72e61b9a15154d5ad2c365623527a35659278f;hb=ab8f306d7c2c49b8116e1af7b355ed2384617ed9;hp=1a55e8a46cdc0ac178b4f656df9ea689a48c676e;hpb=17f6eae9907a122d4472da727ae8b1ac1c40c027;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/modules/private/websites/aten/production.nix b/modules/private/websites/aten/production.nix index 1a55e8a..1f72e61 100644 --- a/modules/private/websites/aten/production.nix +++ b/modules/private/websites/aten/production.nix @@ -1,36 +1,87 @@ -{ lib, pkgs, config, myconfig, ... }: +{ lib, pkgs, config, ... }: let - aten = pkgs.callPackage ./builder.nix { - inherit (pkgs.webapps) aten; - config = myconfig.env.websites.aten.production; - apacheUser = config.services.httpd.Prod.user; - apacheGroup = config.services.httpd.Prod.group; - }; - + secrets = config.myEnv.websites.aten.production; + app = pkgs.webapps.aten.override { environment = secrets.environment; }; cfg = config.myServices.websites.aten.production; + pcfg = config.services.phpApplication; in { options.myServices.websites.aten.production.enable = lib.mkEnableOption "enable Aten's website in production"; config = lib.mkIf cfg.enable { - secrets.keys = aten.keys; + services.duplyBackup.profiles.aten_prod.rootDir = app.varDir; services.webstats.sites = [ { name = "aten.pro"; } ]; + services.phpApplication.apps.aten_prod = { + websiteEnv = "production"; + httpdUser = config.services.httpd.Prod.user; + httpdGroup = config.services.httpd.Prod.group; + httpdWatchFiles = [ + config.secrets.fullPaths."webapps/${app.environment}-aten" + ]; + 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 + ''; + }; - systemd.services.phpfpm-aten_prod.preStart = lib.mkAfter aten.phpFpm.preStart; - systemd.services.phpfpm-aten_prod.after = lib.mkAfter aten.phpFpm.serviceDeps; - systemd.services.phpfpm-aten_prod.wants = aten.phpFpm.serviceDeps; - services.phpfpm.poolConfigs.aten_prod = aten.phpFpm.pool; - system.activationScripts.aten_prod = aten.activationScript; - myServices.websites.webappDirs."${aten.apache.webappName}" = aten.app.webRoot; - services.websites.production.modules = aten.apache.modules; - services.websites.production.vhostConfs.aten = { + secrets.keys = [{ + dest = "webapps/${app.environment}-aten"; + 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.aten_prod = { certName = "aten"; certMainHost = "aten.pro"; - hosts = [ "aten.pro" "www.aten.pro" ]; - root = aten.apache.root; - extraConfig = [ aten.apache.vhostConf ]; + hosts = [ "aten.pro" "www.aten.pro" ]; + root = pcfg.webappDirs.aten_prod; + extraConfig = [ + '' + + SetHandler "proxy:unix:${pcfg.phpListenPaths.aten_prod}|fcgi://localhost" + + + Include ${config.secrets.fullPaths."webapps/${app.environment}-aten"} + + 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 + + '' + ]; }; - services.websites.production.watchPaths = [ - "/var/secrets/webapps/${aten.app.environment}-aten" - ]; }; }