aboutsummaryrefslogblamecommitdiff
path: root/modules/private/websites/isabelle/aten_integration.nix
blob: 6f8f985af6ae77d71d6b1d12ca0be7a9c4d3b412 (plain) (tree)
1
2
3
4
5
6
7
8
9
                            
   
                                                            
                                     
                                                                  


                                                  
                                                             
                                        
    
                                                                                                                           

                                

                                                                                 


                                                    
                         
                                                                     
        





                                                                                                   
                                  








                                                       
                                       
        
                              

      
                     
                                                  
                                             
                                               
                           





                                                                                                                         

                                                
                                         

           
                                                                              
                                  

                                       
                                                              


                             
                                                                                                   

                     
                                                                                












                                                                                                           
                                                                







                                                            


      
{ lib, pkgs, config,  ... }:
let
  secrets = config.myEnv.websites.isabelle.aten_integration;
  app = pkgs.callPackage ./aten_app {
    composerEnv = pkgs.composerEnv.override { php = pkgs.php72; };
    environment = secrets.environment;
    varDir = "/var/lib/isabelle_aten_integration";
  };
  cfg = config.myServices.websites.isabelle.aten_integration;
  pcfg = config.services.phpApplication;
in {
  options.myServices.websites.isabelle.aten_integration.enable = lib.mkEnableOption "enable Aten's website in integration";

  config = lib.mkIf cfg.enable {
    services.duplyBackup.profiles.isabelle_aten_integration.rootDir = app.varDir;
    services.phpApplication.apps.isabelle_aten_integration = {
      websiteEnv = "integration";
      httpdUser = config.services.httpd.Inte.user;
      httpdGroup = config.services.httpd.Inte.group;
      httpdWatchFiles = [
        config.secrets.fullPaths."websites/isabelle/aten_integration"
      ];
      inherit (app) webRoot varDir;
      inherit app;
      serviceDeps = [ "postgresql.service" ];
      preStartActions = [
        "APP_ENV=${app.environment} ./bin/console --env=${app.environment} cache:clear --no-warmup"
      ];
      phpOpenbasedir = [ "/tmp" ];
      phpPool = {
        "php_admin_value[upload_max_filesize]" = "20M";
        "php_admin_value[post_max_size]" = "20M";
        #"php_admin_flag[log_errors]" = "on";
        "pm" = "ondemand";
        "pm.max_children" = "5";
        "pm.process_idle_timeout" = "60";
      };
      phpEnv = {
        SYMFONY_DEBUG_MODE = "\"yes\"";
      };
      phpPackage = pkgs.php72;
    };

    secrets.keys = [{
      dest = "websites/isabelle/aten_integration";
      user = config.services.httpd.Inte.user;
      group = config.services.httpd.Inte.group;
      permissions = "0400";
      text = let
        # cf:
        #   https://secure.php.net/manual/fr/function.parse-url.php
        #   vendor/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php#parseDatabaseUrlQuery
        psql_url = with secrets.postgresql; "pdo-pgsql://${user}:${password}@invalid:${port}/${database}?host=${socket}";
      in ''
        SetEnv APP_ENV      "${app.environment}"
        SetEnv APP_SECRET   "${secrets.secret}"
        SetEnv DATABASE_URL "${psql_url}"
        '';
    }];
    services.websites.env.integration.vhostConfs.isabelle_aten_integration = {
      certName    = "integration";
      addToCerts  = true;
      hosts       = [ "dev.aten.pro" ];
      root        = pcfg.webappDirs.isabelle_aten_integration;
      extraConfig = [
        ''
        <FilesMatch "\.php$">
          SetHandler "proxy:unix:${pcfg.phpListenPaths.isabelle_aten_integration}|fcgi://localhost"
        </FilesMatch>

        Include ${config.secrets.fullPaths."websites/isabelle/aten_integration"}

        <Location />
          Use LDAPConnect
          Require ldap-group   cn=dev.aten.pro,cn=httpd,ou=services,dc=immae,dc=eu
          ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>"
        </Location>

        <Location /backend>
          Use LDAPConnect
          Require ldap-group   cn=dev.aten.pro,cn=httpd,ou=services,dc=immae,dc=eu
          ErrorDocument 401 "<html><meta http-equiv=\"refresh\" content=\"0;url=https://aten.pro\"></html>"
        </Location>

        <Directory ${pcfg.webappDirs.isabelle_aten_integration}>
          Options Indexes FollowSymLinks MultiViews Includes
          AllowOverride All
          Require all granted
          DirectoryIndex index.php
          FallbackResource /index.php
        </Directory>
        ''
      ];
    };
  };
}