]> git.immae.eu Git - perso/Immae/Config/Nix.git/blame - modules/private/websites/ludivine/production.nix
Refactor websites
[perso/Immae/Config/Nix.git] / modules / private / websites / ludivine / production.nix
CommitLineData
ab8f306d 1{ lib, pkgs, config, ... }:
f8026b6e 2let
d3452fc5
IB
3 secrets = config.myEnv.websites.ludivine.production;
4 app = pkgs.callPackage ./app {
5 environment = secrets.environment;
6 varDir = "/var/lib/ludivine_production";
7 secretsPath = config.secrets.fullPaths."websites/ludivine/production";
8 };
8164ed90 9 pcfg = config.services.phpApplication;
d3452fc5 10 cfg = config.myServices.websites.ludivine.production;
f8026b6e 11in {
d3452fc5 12 options.myServices.websites.ludivine.production.enable = lib.mkEnableOption "enable Ludivine's website in production";
f8026b6e
IB
13
14 config = lib.mkIf cfg.enable {
d3452fc5 15 services.duplyBackup.profiles.ludivine_production.rootDir = app.varDir;
f8026b6e 16 services.webstats.sites = [ { name = "ludivinecassal.com"; } ];
d3452fc5 17 services.phpApplication.apps.ludivine_production = {
8164ed90
IB
18 websiteEnv = "production";
19 httpdUser = config.services.httpd.Prod.user;
20 httpdGroup = config.services.httpd.Prod.group;
21 inherit (app) webRoot varDir;
22 varDirPaths = {
23 "tmp" = "0700";
24 };
25 inherit app;
26 serviceDeps = [ "mysql.service" ];
27 preStartActions = [
28 "./bin/console --env=${app.environment} cache:clear --no-warmup"
29 ];
30 phpOpenbasedir = [ "/tmp" ];
5400b9b6
IB
31 phpPool = {
32 "php_admin_value[upload_max_filesize]" = "20M";
33 "php_admin_value[post_max_size]" = "20M";
34 #"php_admin_flag[log_errors]" = "on";
35 "pm" = "dynamic";
36 "pm.max_children" = "20";
37 "pm.start_servers" = "2";
38 "pm.min_spare_servers" = "1";
39 "pm.max_spare_servers" = "3";
40 };
8164ed90 41 phpWatchFiles = [
d3452fc5 42 config.secrets.fullPaths."websites/ludivine/production"
8164ed90 43 ];
d3452fc5
IB
44 phpEnv = {
45 PATH = lib.makeBinPath [
46 # below ones don't need to be in the PATH but they’re used in
47 # secrets
48 pkgs.imagemagick pkgs.sass pkgs.ruby
49 ];
50 };
8164ed90
IB
51 };
52
53 secrets.keys = [
54 {
d3452fc5 55 dest = "websites/ludivine/production";
8164ed90
IB
56 user = config.services.httpd.Prod.user;
57 group = config.services.httpd.Prod.group;
58 permissions = "0400";
59 text = ''
60 # This file is auto-generated during the composer install
61 parameters:
62 database_host: ${secrets.mysql.host}
63 database_port: ${secrets.mysql.port}
ab8f306d 64 database_name: ${secrets.mysql.database}
8164ed90
IB
65 database_user: ${secrets.mysql.user}
66 database_password: ${secrets.mysql.password}
67 database_server_version: ${pkgs.mariadb.mysqlVersion}
68 mailer_transport: smtp
69 mailer_host: 127.0.0.1
70 mailer_user: null
71 mailer_password: null
72 secret: ${secrets.secret}
73 ldap_host: ldap.immae.eu
74 ldap_port: 636
75 ldap_version: 3
76 ldap_ssl: true
77 ldap_tls: false
78 ldap_user_bind: 'uid={username},ou=users,dc=immae,dc=eu'
79 ldap_base_dn: 'dc=immae,dc=eu'
80 ldap_search_dn: '${secrets.ldap.dn}'
81 ldap_search_password: '${secrets.ldap.password}'
ab8f306d 82 ldap_search_filter: '${secrets.ldap.filter}'
8164ed90
IB
83 leapt_im:
84 binary_path: ${pkgs.imagemagick}/bin
85 assetic:
86 sass: ${pkgs.sass}/bin/sass
87 ruby: ${pkgs.ruby}/bin/ruby
88 '';
89 }
90 ];
f8026b6e 91
d3452fc5
IB
92 services.websites.env.production.vhostConfs.ludivine_production = {
93 certName = "ludivine";
f8026b6e
IB
94 certMainHost = "ludivinecassal.com";
95 hosts = ["ludivinecassal.com" "www.ludivinecassal.com" ];
d3452fc5 96 root = pcfg.webappDirs.ludivine_production;
8164ed90
IB
97 extraConfig = [
98 ''
33b5010f
IB
99 RewriteEngine on
100 RewriteCond "%{HTTP_HOST}" "!^ludivinecassal\.com$" [NC]
101 RewriteRule ^(.+)$ https://ludivinecassal.com$1 [R=302,L]
102
8164ed90 103 <FilesMatch "\.php$">
d3452fc5 104 SetHandler "proxy:unix:${pcfg.phpListenPaths.ludivine_production}|fcgi://localhost"
8164ed90
IB
105 </FilesMatch>
106
107 Use Stats ludivinecassal.com
108
d3452fc5 109 <Directory ${pcfg.webappDirs.ludivine_production}>
8164ed90
IB
110 Options Indexes FollowSymLinks MultiViews Includes
111 AllowOverride All
112 Require all granted
113 </Directory>
114 ''
115 ];
17f6eae9 116 };
f8026b6e
IB
117 };
118}