aboutsummaryrefslogtreecommitdiff
path: root/modules/private/websites/emilia/richie.nix
blob: f7b4f8dbd5860ab6cc5ecad0634a652e22b46c08 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{ lib, config, pkgs, ... }:
let
  cfg = config.myServices.websites.emilia.richie_production;
  vardir = "/var/lib/richie_production";
  richieSrc = pkgs.stdenv.mkDerivation (pkgs.mylibs.fetchedGitPrivate ./richie.json // {
    phases = "installPhase";
    installPhase = ''
      cp -a $src $out
      chmod -R u+w $out
      ln -sf ${vardir}/files $out/
      ln -sf ${vardir}/drapeaux $out/images/
      ln -sf ${vardir}/photos $out/
      sed -i "s@localedef --list-archive@localedef --list-archive /run/current-system/sw/lib/locale/locale-archive@" $out/admin/parametres.php
      '';
  });
in
{
  options.myServices.websites.emilia.richie_production.enable = lib.mkEnableOption "enable Richie's website";
  config = lib.mkIf cfg.enable {
    services.duplyBackup.profiles.richie_production.rootDir = vardir;
    services.webstats.sites = [ { name = "europe-richie.org"; } ];

    secrets.keys = [{
      dest = "webapps/prod-richie";
      user = "wwwrun";
      group = "wwwrun";
      permissions = "0400";
      text = with config.myEnv.websites.richie; ''
        <?php

        $hote_sql = '${mysql.host}';
        $login_sql = '${mysql.user}';
        $bdd_sql = '${mysql.database}';
        $mdp_sql = '${mysql.password}';

        $db = mysqli_connect($hote_sql,$login_sql,$mdp_sql);
        unset($mdp_sql);

        $smtp_mailer->Auth('${smtp_mailer.user}', '${smtp_mailer.password}');
        ?>
        '';
    }];
    myServices.websites.webappDirs.richie_production = richieSrc;
    system.activationScripts.richie_production = {
      deps = [ "httpd" ];
      text = ''
        install -m 0755 -o wwwrun -g wwwrun -d /var/lib/php/sessions/richie_production
        install -m 0755 -o wwwrun -g wwwrun -d ${vardir}
        '';
    };
    services.phpfpm.pools.richie_production = {
      listen = "/run/phpfpm/richie_production.sock";
      extraConfig = ''
        user = wwwrun
        group = wwwrun
        listen.owner = wwwrun
        listen.group = wwwrun

        pm = ondemand
        pm.max_children = 5
        pm.process_idle_timeout = 60

        env[PATH] = /run/current-system/sw/bin:${lib.makeBinPath [ pkgs.imagemagick ]}
        env[BDD_CONNECT] = "/var/secrets/webapps/prod-richie"
        php_admin_value[open_basedir] = "${vardir}:/var/lib/php/sessions/richie_production:/var/secrets/webapps/prod-richie:${richieSrc}:/tmp"
        php_admin_value[session.save_path] = "/var/lib/php/sessions/richie_production"
        '';
      phpOptions = config.services.phpfpm.phpOptions + ''
        date.timezone = 'Europe/Paris'
        extension=${pkgs.php}/lib/php/extensions/mysqli.so
        '';
    };
    services.websites.env.production.modules = [ "proxy_fcgi" ];
    services.websites.env.production.vhostConfs.richie_production = {
      certName    = "richie";
      addToCerts  = true;
      certMainHost = "europe-richie.org";
      hosts       = [ "europe-richie.org" "www.europe-richie.org" ];
      root        = "/run/current-system/webapps/richie_production";
      extraConfig = [
        ''
        Use Stats europe-richie.org
        ErrorDocument 404 /404.html
        <LocationMatch "^/files/.*/admin/">
          Require all denied
        </LocationMatch>
        <Directory /run/current-system/webapps/richie_production>
          DirectoryIndex index.php index.htm index.html
          Options Indexes FollowSymLinks MultiViews Includes
          AllowOverride None
          Require all granted

          <FilesMatch "\.php$">
            SetHandler "proxy:unix:/run/phpfpm/richie_production.sock|fcgi://localhost"
          </FilesMatch>
        </Directory>
          ''
      ];
    };
  };
}