]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - modules/private/websites/piedsjaloux/production.nix
Refactor websites
[perso/Immae/Config/Nix.git] / modules / private / websites / piedsjaloux / production.nix
CommitLineData
ab8f306d 1{ lib, pkgs, config, ... }:
f8026b6e 2let
ab8f306d 3 secrets = config.myEnv.websites.piedsjaloux.production;
d3452fc5
IB
4 app = pkgs.callPackage ./app {
5 environment = secrets.environment;
6 varDir = "/var/lib/piedsjaloux_production";
7 secretsPath = config.secrets.fullPaths."websites/piedsjaloux/production";
8 };
f8026b6e 9 cfg = config.myServices.websites.piedsjaloux.production;
8164ed90 10 pcfg = config.services.phpApplication;
d3452fc5 11 texlive = pkgs.texlive.combine { inherit (pkgs.texlive) attachfile preprint scheme-small; };
f8026b6e
IB
12in {
13 options.myServices.websites.piedsjaloux.production.enable = lib.mkEnableOption "enable PiedsJaloux's website in production";
14
15 config = lib.mkIf cfg.enable {
d3452fc5 16 services.duplyBackup.profiles.piedsjaloux_production.rootDir = app.varDir;
f8026b6e 17 services.webstats.sites = [ { name = "piedsjaloux.fr"; } ];
d3452fc5 18 services.phpApplication.apps.piedsjaloux_production = {
8164ed90
IB
19 websiteEnv = "production";
20 httpdUser = config.services.httpd.Prod.user;
21 httpdGroup = config.services.httpd.Prod.group;
22 inherit (app) webRoot varDir;
23 varDirPaths = {
24 "tmp" = "0700";
25 };
26 inherit app;
27 serviceDeps = [ "mysql.service" ];
28 preStartActions = [
29 "./bin/console --env=${app.environment} cache:clear --no-warmup"
30 ];
31 phpOpenbasedir = [ "/tmp" ];
5400b9b6
IB
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 phpEnv = {
d3452fc5
IB
43 PATH = lib.makeBinPath [
44 pkgs.apg pkgs.unzip
45 # below ones don't need to be in the PATH but they’re used in
46 # secrets
47 pkgs.imagemagick texlive
48 ];
5400b9b6 49 };
8164ed90 50 phpWatchFiles = [
d3452fc5 51 app.secretsPath
8164ed90
IB
52 ];
53 };
54
55 secrets.keys = [
56 {
d3452fc5 57 dest = "websites/piedsjaloux/production";
8164ed90
IB
58 user = config.services.httpd.Prod.user;
59 group = config.services.httpd.Prod.group;
60 permissions = "0400";
61 text = ''
62 # This file is auto-generated during the composer install
63 parameters:
64 database_host: ${secrets.mysql.host}
65 database_port: ${secrets.mysql.port}
ab8f306d 66 database_name: ${secrets.mysql.database}
8164ed90
IB
67 database_user: ${secrets.mysql.user}
68 database_password: ${secrets.mysql.password}
69 database_server_version: ${pkgs.mariadb.mysqlVersion}
70 mailer_transport: smtp
71 mailer_host: 127.0.0.1
72 mailer_user: null
73 mailer_password: null
74 secret: ${secrets.secret}
d3452fc5 75 pdflatex: "${texlive}/bin/pdflatex"
8164ed90
IB
76 leapt_im:
77 binary_path: ${pkgs.imagemagick}/bin
78 '';
79 }
80 ];
f8026b6e 81
d3452fc5 82 services.websites.env.production.vhostConfs.piedsjaloux_production = {
f8026b6e
IB
83 certName = "piedsjaloux";
84 certMainHost = "piedsjaloux.fr";
85 hosts = [ "piedsjaloux.fr" "www.piedsjaloux.fr" ];
d3452fc5 86 root = pcfg.webappDirs.piedsjaloux_production;
8164ed90
IB
87 extraConfig = [
88 ''
33b5010f
IB
89 RewriteEngine on
90 RewriteCond "%{HTTP_HOST}" "!^www.piedsjaloux\.fr$" [NC]
91 RewriteRule ^(.+)$ https://www.piedsjaloux.fr$1 [R=302,L]
92
8164ed90 93 <FilesMatch "\.php$">
d3452fc5 94 SetHandler "proxy:unix:${pcfg.phpListenPaths.piedsjaloux_production}|fcgi://localhost"
8164ed90
IB
95 </FilesMatch>
96
97 Use Stats piedsjaloux.fr
98
d3452fc5 99 <Directory ${pcfg.webappDirs.piedsjaloux_production}>
8164ed90
IB
100 Options Indexes FollowSymLinks MultiViews Includes
101 AllowOverride All
102 Require all granted
103 </Directory>
104 ''
105 ];
f8026b6e
IB
106 };
107 };
108}