]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/websites/emilia/richie.nix
Add Richie website
[perso/Immae/Config/Nix.git] / modules / private / websites / emilia / richie.nix
1 { lib, config, pkgs, ... }:
2 let
3 cfg = config.myServices.websites.emilia.richie_production;
4 vardir = "/var/lib/richie_production";
5 richieSrc = pkgs.stdenv.mkDerivation (pkgs.mylibs.fetchedGitPrivate ./richie.json // {
6 phases = "installPhase";
7 installPhase = ''
8 cp -a $src $out
9 chmod -R u+w $out
10 ln -sf ${vardir}/files $out/
11 ln -sf ${vardir}/drapeaux $out/images/
12 ln -sf ${vardir}/photos $out/
13 sed -i "s@localedef --list-archive@localedef --list-archive /run/current-system/sw/lib/locale/locale-archive@" $out/admin/parametres.php
14 '';
15 });
16 in
17 {
18 options.myServices.websites.emilia.richie_production.enable = lib.mkEnableOption "enable Richie's website";
19 config = lib.mkIf cfg.enable {
20 services.duplyBackup.profiles.richie_production.rootDir = vardir;
21 services.webstats.sites = [ { name = "europe-richie.org"; } ];
22
23 secrets.keys = [{
24 dest = "webapps/prod-richie";
25 user = "wwwrun";
26 group = "wwwrun";
27 permissions = "0400";
28 text = with config.myEnv.websites.richie; ''
29 <?php
30
31 $hote_sql = '${mysql.host}';
32 $login_sql = '${mysql.user}';
33 $bdd_sql = '${mysql.database}';
34 $mdp_sql = '${mysql.password}';
35
36 $db = mysqli_connect($hote_sql,$login_sql,$mdp_sql);
37 unset($mdp_sql);
38
39 $smtp_mailer->Auth('${smtp_mailer.user}', '${smtp_mailer.password}');
40 ?>
41 '';
42 }];
43 myServices.websites.webappDirs.richie_production = richieSrc;
44 system.activationScripts.richie_production = {
45 deps = [ "httpd" ];
46 text = ''
47 install -m 0755 -o wwwrun -g wwwrun -d /var/lib/php/sessions/richie_production
48 install -m 0755 -o wwwrun -g wwwrun -d ${vardir}
49 '';
50 };
51 services.phpfpm.pools.richie_production = {
52 listen = "/run/phpfpm/richie_production.sock";
53 extraConfig = ''
54 user = wwwrun
55 group = wwwrun
56 listen.owner = wwwrun
57 listen.group = wwwrun
58
59 pm = ondemand
60 pm.max_children = 5
61 pm.process_idle_timeout = 60
62
63 env[PATH] = /run/current-system/sw/bin:${lib.makeBinPath [ pkgs.imagemagick ]}
64 env[BDD_CONNECT] = "/var/secrets/webapps/prod-richie"
65 php_admin_value[open_basedir] = "${vardir}:/var/lib/php/sessions/richie_production:/var/secrets/webapps/prod-richie:${richieSrc}:/tmp"
66 php_admin_value[session.save_path] = "/var/lib/php/sessions/richie_production"
67 '';
68 phpOptions = config.services.phpfpm.phpOptions + ''
69 date.timezone = 'Europe/Paris'
70 extension=${pkgs.php}/lib/php/extensions/mysqli.so
71 '';
72 };
73 services.websites.env.production.modules = [ "proxy_fcgi" ];
74 services.websites.env.production.vhostConfs.richie_production = {
75 certName = "richie";
76 addToCerts = true;
77 certMainHost = "europe-richie.org";
78 hosts = [ "europe-richie.org" "www.europe-richie.org" ];
79 root = "/run/current-system/webapps/richie_production";
80 extraConfig = [
81 ''
82 Use Stats europe-richie.org
83 ErrorDocument 404 /404.html
84 <LocationMatch "^/files/.*/admin/">
85 Require all denied
86 </LocationMatch>
87 <Directory /run/current-system/webapps/richie_production>
88 DirectoryIndex index.php index.htm index.html
89 Options Indexes FollowSymLinks MultiViews Includes
90 AllowOverride None
91 Require all granted
92
93 <FilesMatch "\.php$">
94 SetHandler "proxy:unix:/run/phpfpm/richie_production.sock|fcgi://localhost"
95 </FilesMatch>
96 </Directory>
97 ''
98 ];
99 };
100 };
101 }