aboutsummaryrefslogblamecommitdiff
path: root/nixops/modules/websites/ftp/jerome.nix
blob: 18d16a11757ea69670330b7cb968b0bf34d01558 (plain) (tree)






























                                                                                       

                                         

                       
                           
               












                                                                                              
         

                                                                       
                                             









                                            

                                                                                             



































                                                                                        
{ lib, pkgs, config, myconfig, mylibs, ... }:
let
    adminer = pkgs.callPackage ../commons/adminer.nix {};
    cfg = config.services.myWebsites.Jerome;
    varDir = "/var/lib/ftp/jerome";
    env = myconfig.env.websites.jerome;
in {
  options.services.myWebsites.Jerome = {
    production = {
      enable = lib.mkEnableOption "enable Jerome's website";
    };
  };

  imports = [
    ../commons/stats.nix
  ];

  config = lib.mkIf cfg.production.enable {
    services.myWebsites.commons.stats.enable = true;
    services.myWebsites.commons.stats.sites = [
      {
        name = "naturaloutil.immae.eu";
        conf = ./jerome_goaccess.conf;
      }
    ];

    security.acme.certs."ftp".extraDomains."naturaloutil.immae.eu" = null;
    security.acme.certs."naturaloutil" = config.services.myCertificates.certConfig // {
      domain = "naturaloutil.immae.eu";
    };

    mySecrets.keys = [{
      dest = "webapps/prod-naturaloutil";
      user = "wwwrun";
      group = "wwwrun";
      permissions = "0400";
      text = ''
        <?php
        $mysql_user = '${env.mysql.user}' ;
        $mysql_server = '${env.mysql.host}' ;
        $mysql_base = '${env.mysql.name}' ;
        $mysql_password = '${env.mysql.password}' ;
        //connect to db
        $db = mysqli_init();
        ${if env.mysql.host != "localhost" then ''
        mysqli_options ($db, MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true);
        $db->ssl_set(NULL, NULL, "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt", NULL, NULL);
        '' else ""}
        $database = connect_db($db, $mysql_server, $mysql_base, $mysql_user, $mysql_password);
        ?>
      '';
    }];
    services.myPhpfpm.serviceDependencies.jerome = [ "mysql.service" ];
    services.myPhpfpm.poolConfigs.jerome = ''
      listen = /run/phpfpm/naturaloutil.sock
      user = wwwrun
      group = wwwrun
      listen.owner = wwwrun
      listen.group = wwwrun

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

      env[BDD_CONNECT] = "/var/secrets/webapps/prod-naturaloutil"
      php_admin_value[open_basedir] = "/var/secrets/webapps/prod-naturaloutil:${varDir}:/tmp"
      '';
    services.myPhpfpm.poolPhpConfigs.jerome = ''
      extension=${pkgs.php}/lib/php/extensions/mysqli.so
      '';
    services.myWebsites.production.modules = adminer.apache.modules ++ [ "proxy_fcgi" ];
    services.myWebsites.production.vhostConfs.naturaloutil = {
      certName    = "naturaloutil";
      hosts       = ["naturaloutil.immae.eu" ];
      root        = varDir;
      extraConfig = [
        adminer.apache.vhostConf
        ''
        Use Stats naturaloutil.immae.eu
        ServerAdmin ${env.server_admin}
        ErrorLog "${varDir}/logs/error_log"
        CustomLog "${varDir}/logs/access_log" combined

        <FilesMatch "\.php$">
          SetHandler "proxy:unix:/run/phpfpm/naturaloutil.sock|fcgi://localhost"
        </FilesMatch>

        <Directory ${varDir}/logs>
          AllowOverride None
          Require all denied
        </Directory>
        <Directory ${varDir}>
          DirectoryIndex index.php index.htm index.html
          Options Indexes FollowSymLinks MultiViews Includes
          AllowOverride None
          Require all granted
        </Directory>
          ''
      ];
    };
  };
}