]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - modules/private/websites/jerome/naturaloutil.nix
Refactor websites
[perso/Immae/Config/Nix.git] / modules / private / websites / jerome / naturaloutil.nix
diff --git a/modules/private/websites/jerome/naturaloutil.nix b/modules/private/websites/jerome/naturaloutil.nix
new file mode 100644 (file)
index 0000000..8bbb49e
--- /dev/null
@@ -0,0 +1,100 @@
+{ lib, pkgs, config,  ... }:
+let
+  adminer = pkgs.callPackage ../commons/adminer.nix { inherit config; };
+  cfg = config.myServices.websites.jerome.naturaloutil;
+  varDir = "/var/lib/ftp/jerome";
+  env = config.myEnv.websites.jerome;
+  apacheUser = config.services.httpd.Prod.user;
+  apacheGroup = config.services.httpd.Prod.group;
+  secretsPath = config.secrets.fullPaths."websites/jerome/naturaloutil";
+in {
+  options.myServices.websites.jerome.naturaloutil.enable = lib.mkEnableOption "enable Jerome Naturaloutil's website";
+
+  config = lib.mkIf cfg.enable {
+    services.webstats.sites = [ { name = "naturaloutil.immae.eu"; } ];
+
+    security.acme.certs."ftp".extraDomains."naturaloutil.immae.eu" = null;
+
+    secrets.keys = [{
+      dest = "websites/jerome/naturaloutil";
+      user = apacheUser;
+      group = apacheGroup;
+      permissions = "0400";
+      text = ''
+        <?php
+        $mysql_user = '${env.mysql.user}' ;
+        $mysql_server = '${env.mysql.host}' ;
+        $mysql_base = '${env.mysql.database}' ;
+        $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);
+        ?>
+      '';
+    }];
+    system.activationScripts.jerome_naturaloutil = {
+      deps = [ "httpd" ];
+      text = ''
+        install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d /var/lib/php/sessions/jerome_naturaloutil
+        '';
+    };
+    systemd.services.phpfpm-jerome_naturaloutil.after = lib.mkAfter [ "mysql.service" ];
+    systemd.services.phpfpm-jerome_naturaloutil.wants = [ "mysql.service" ];
+    services.phpfpm.pools.jerome_naturaloutil = {
+      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]" = "/var/lib/php/sessions/jerome_naturaloutil:${secretsPath}:${varDir}:/tmp";
+        "php_admin_value[session.save_path]" = "/var/lib/php/sessions/jerome_naturaloutil";
+      };
+      phpEnv = {
+        BDD_CONNECT = secretsPath;
+      };
+      phpOptions = config.services.phpfpm.phpOptions + ''
+        extension=${pkgs.php}/lib/php/extensions/mysqli.so
+        '';
+    };
+    services.websites.env.production.modules = adminer.apache.modules ++ [ "proxy_fcgi" ];
+    services.websites.env.production.vhostConfs.jerome_naturaloutil = {
+      certName     = "jerome";
+      certMainHost = "naturaloutil.immae.eu";
+      hosts        = ["naturaloutil.immae.eu" ];
+      root         = varDir;
+      extraConfig  = [
+        (adminer.apache.vhostConf null)
+        ''
+        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:${config.services.phpfpm.pools.jerome_naturaloutil.socket}|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>
+          ''
+      ];
+    };
+  };
+}