]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/websites/isabelle/aten_production.nix
Add alternate cloud storage for daily backups
[perso/Immae/Config/Nix.git] / modules / private / websites / isabelle / aten_production.nix
1 { lib, pkgs, config, ... }:
2 let
3 secrets = config.myEnv.websites.isabelle.aten_production;
4 app = pkgs.callPackage ./aten_app {
5 composerEnv = pkgs.composerEnv.override { php = pkgs.php72; };
6 environment = secrets.environment;
7 varDir = "/var/lib/isabelle_aten_production";
8 };
9 cfg = config.myServices.websites.isabelle.aten_production;
10 pcfg = config.services.phpApplication;
11 in {
12 options.myServices.websites.isabelle.aten_production.enable = lib.mkEnableOption "enable Aten's website in production";
13
14 config = lib.mkIf cfg.enable {
15 services.duplyBackup.profiles.isabelle_aten_production.rootDir = app.varDir;
16 services.duplyBackup.profiles.isabelle_aten_production.remotes = ["eriomem" "ovh"];
17 services.webstats.sites = [ { name = "aten.pro"; } ];
18 services.phpApplication.apps.isabelle_aten_production = {
19 websiteEnv = "production";
20 httpdUser = config.services.httpd.Prod.user;
21 httpdGroup = config.services.httpd.Prod.group;
22 httpdWatchFiles = [
23 config.secrets.fullPaths."websites/isabelle/aten_production"
24 ];
25 inherit (app) webRoot varDir;
26 inherit app;
27 serviceDeps = [ "postgresql.service" ];
28 preStartActions = [
29 "APP_ENV=${app.environment} ./bin/console --env=${app.environment} cache:clear --no-warmup"
30 ];
31 phpOpenbasedir = [ "/tmp" ];
32 phpPool = {
33 "php_admin_value[upload_max_filesize]" = "20M";
34 "php_admin_value[post_max_size]" = "20M";
35 #"php_admin_flag[log_errors]" = "on";
36 "pm" = "dynamic";
37 "pm.max_children" = "20";
38 "pm.start_servers" = "2";
39 "pm.min_spare_servers" = "1";
40 "pm.max_spare_servers" = "3";
41 };
42 phpPackage = pkgs.php72;
43 };
44
45 secrets.keys = [{
46 dest = "websites/isabelle/aten_production";
47 user = config.services.httpd.Prod.user;
48 group = config.services.httpd.Prod.group;
49 permissions = "0400";
50 text = let
51 # cf:
52 # https://secure.php.net/manual/fr/function.parse-url.php
53 # vendor/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php#parseDatabaseUrlQuery
54 psql_url = with secrets.postgresql; "pdo-pgsql://${user}:${password}@invalid:${port}/${database}?host=${socket}";
55 in ''
56 SetEnv APP_ENV "${app.environment}"
57 SetEnv APP_SECRET "${secrets.secret}"
58 SetEnv DATABASE_URL "${psql_url}"
59 '';
60 }];
61 services.websites.env.production.vhostConfs.isabelle_aten_production = {
62 certName = "isabelle";
63 certMainHost = "aten.pro";
64 hosts = [ "aten.pro" "www.aten.pro" ];
65 root = pcfg.webappDirs.isabelle_aten_production;
66 extraConfig = [
67 ''
68 <FilesMatch "\.php$">
69 SetHandler "proxy:unix:${pcfg.phpListenPaths.isabelle_aten_production}|fcgi://localhost"
70 </FilesMatch>
71
72 Include ${config.secrets.fullPaths."websites/isabelle/aten_production"}
73
74 Use Stats aten.pro
75
76 <Location /backend>
77 Use LDAPConnect
78 Require ldap-group cn=aten.pro,cn=httpd,ou=services,dc=immae,dc=eu
79 ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>"
80 </Location>
81
82 <Directory ${pcfg.webappDirs.isabelle_aten_production}>
83 Options Indexes FollowSymLinks MultiViews Includes
84 AllowOverride All
85 Require all granted
86 DirectoryIndex index.php
87 FallbackResource /index.php
88 </Directory>
89 ''
90 ];
91 };
92 };
93 }