aboutsummaryrefslogtreecommitdiff
path: root/modules/private/websites/richie/production.nix
blob: e95df300cf94db8a8b1faaca8a2afc49695a7ff7 (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
102
103
104
105
106
107
108
{ lib, config, pkgs, ... }:
let
  cfg = config.myServices.websites.richie.production;
  vardir = "/var/lib/richie_production";
  richieSrc = pkgs.stdenv.mkDerivation rec {
    version = pkgs.sources.websites-richie-app.version;
    pname = "richie";
    name = "${pname}-${version}";
    src = pkgs.sources.websites-richie-app;
    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
      '';
  };
  secretPath = config.secrets.fullPaths."websites/richie/production";
  apacheUser = config.services.httpd.Prod.user;
  apacheGroup = config.services.httpd.Prod.group;
in
{
  options.myServices.websites.richie.production.enable = lib.mkEnableOption "enable Richie's website";
  config = lib.mkIf cfg.enable {
    services.duplyBackup.profiles.richie_production.rootDir = vardir;
    services.duplyBackup.profiles.richie_production.remotes = ["eriomem" "ovh"];
    services.webstats.sites = [ { name = "europe-richie.org"; } ];

    secrets.keys."websites/richie/production" = {
      user = apacheUser;
      group = apacheGroup;
      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}');
        ?>
        '';
    };
    system.activationScripts.richie_production = {
      deps = [ "httpd" ];
      text = ''
        install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d /var/lib/php/sessions/richie_production
        install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d ${vardir}
        '';
    };
    services.phpfpm.pools.richie_production = {
      user = apacheUser;
      group = apacheGroup;
      settings = {
        "listen.owner" = apacheUser;
        "listen.group" = apacheGroup;

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

        "php_admin_value[open_basedir]" = "${vardir}:/var/lib/php/sessions/richie_production:${secretPath}:${richieSrc}:/tmp";
        "php_admin_value[session.save_path]" = "/var/lib/php/sessions/richie_production";
      };
      phpEnv = {
        PATH = "/run/current-system/sw/bin:${lib.makeBinPath [ pkgs.imagemagick ]}";
        BDD_CONNECT = secretPath;
      };
      phpOptions = config.services.phpfpm.phpOptions + ''
        date.timezone = 'Europe/Paris'
        '';
      phpPackage = pkgs.php72;
    };
    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        = richieSrc;
      extraConfig = [
        ''
        Use Stats europe-richie.org
        ErrorDocument 404 /404.html
        <LocationMatch "^/files/.*/admin/">
          Require all denied
        </LocationMatch>
        <Directory ${richieSrc}>
          DirectoryIndex index.php index.htm index.html
          Options Indexes FollowSymLinks MultiViews Includes
          AllowOverride None
          Require all granted

          <FilesMatch "\.php$">
            SetHandler "proxy:unix:${config.services.phpfpm.pools.richie_production.socket}|fcgi://localhost"
          </FilesMatch>
        </Directory>
          ''
      ];
    };
  };
}