From f70118c33f40b7394fb8601278b9e4e909249bd6 Mon Sep 17 00:00:00 2001 From: Asmir A Date: Mon, 3 Jul 2023 22:48:55 +0200 Subject: [PATCH] add magento2 module --- magento2-nginx.nix | 77 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 magento2-nginx.nix diff --git a/magento2-nginx.nix b/magento2-nginx.nix new file mode 100644 index 0000000..37a96af --- /dev/null +++ b/magento2-nginx.nix @@ -0,0 +1,77 @@ +{ + pkgs, + lib, + config, + ... +}: let + app = "magento2"; + domain = "127.0.0.1"; + dataDir = config.users.users.akill.home + "/proj/magento2/magento/pub"; +in { + services = { + phpfpm.pools.${app} = { + user = "akill"; + group = "users"; + settings = { + "listen.owner" = config.services.nginx.user; + "pm" = "dynamic"; + "pm.max_children" = 32; + "pm.max_requests" = 500; + "pm.start_servers" = 2; + "pm.min_spare_servers" = 2; + "pm.max_spare_servers" = 5; + "php_admin_value[error_log]" = "stderr"; + "php_admin_flag[log_errors]" = true; + "catch_workers_output" = true; + }; + phpEnv."PATH" = lib.makeBinPath [pkgs.php]; + }; + + nginx = { + user = "akill"; + group = "users"; + enable = true; + virtualHosts.${domain}.locations."/" = { + root = dataDir; + extraConfig = '' + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass unix:${config.services.phpfpm.pools.${app}.socket}; + include ${pkgs.nginx}/conf/fastcgi_params; + include ${pkgs.nginx}/conf/fastcgi.conf; + ''; + }; + }; + + mysql = { + enable = true; + package = pkgs.mysql; + settings.mysqld.port = 3306; + initialDatabases = [{name = "magento2";}]; + ensureUsers = [ + { + name = "magento2"; + ensurePermissions = {"magento2.*" = "ALL PRIVILEGES";}; + } + ]; + }; + + opensearch.enable = true; + + postgresql = { + enable = true; + enableTCPIP = true; + authentication = pkgs.lib.mkOverride 10 '' + local all all trust + host all all 127.0.0.1/32 trust + host all all ::1/128 trust + ''; + initialScript = pkgs.writeText "backend-initScript" '' + CREATE ROLE magento2 WITH LOGIN PASSWORD 'magento2' CREATEDB; + CREATE DATABASE magento2; + GRANT ALL PRIVILEGES ON DATABASE magento2 TO magento2; + ''; + }; + }; + + systemd.services.phpfpm-magento2.serviceConfig.ProtectHome = lib.mkForce false; +}