commit ae5dedba4f054cea6f37d5935b4ba1ec21895396
parent ebf06090a36e7b4fe6b06e46a2f716ba6ff1d1a9
Author: Nikolay Korotkiy <sikmir@disroot.org>
Date: Tue, 12 Nov 2024 18:28:16 +0400
Add level0 module
Diffstat:
2 files changed, 76 insertions(+), 0 deletions(-)
diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix
@@ -1,4 +1,5 @@
{
+ level0 = ./services/level0.nix;
mbtileserver = ./services/mbtileserver.nix;
tracks_storage_server = ./services/tracks_storage_server.nix;
}
diff --git a/modules/nixos/services/level0.nix b/modules/nixos/services/level0.nix
@@ -0,0 +1,75 @@
+{
+ config,
+ lib,
+ pkgs,
+ ...
+}:
+
+with lib;
+
+let
+ cfg = config.services.level0;
+in
+{
+ options.services.level0 = {
+ enable = mkEnableOption "level0";
+ package = mkPackageOption pkgs "level0" { };
+ nginx = mkOption {
+ default = { };
+ description = ''
+ Configuration for nginx reverse proxy.
+ '';
+ type = types.submodule {
+ options = {
+ enable = mkOption {
+ type = types.bool;
+ default = false;
+ description = ''
+ Configure the nginx reverse proxy settings.
+ '';
+ };
+ hostName = mkOption {
+ type = types.str;
+ description = ''
+ The hostname use to setup the virtualhost configuration
+ '';
+ };
+ };
+ };
+ };
+ };
+
+ config = mkIf cfg.enable (mkMerge [
+ {
+ services.phpfpm.pools.level0 = {
+ user = "nobody";
+ settings = {
+ "pm" = "dynamic";
+ "listen.owner" = config.services.nginx.user;
+ "pm.max_children" = 5;
+ "pm.start_servers" = 2;
+ "pm.min_spare_servers" = 1;
+ "pm.max_spare_servers" = 3;
+ "pm.max_requests" = 500;
+ "security.limit_extensions" = ".php .js";
+ };
+ };
+ }
+ (mkIf cfg.nginx.enable {
+ services.nginx = {
+ enable = true;
+ virtualHosts."${cfg.nginx.hostName}" = {
+ locations."/" = {
+ root = "${cfg.package}/share/php/level0/www";
+ extraConfig = ''
+ fastcgi_split_path_info ^(.+\.php)(/.+)$;
+ fastcgi_pass unix:${config.services.phpfpm.pools.level0.socket};
+ fastcgi_index index.php;
+ include ${config.services.nginx.package}/conf/fastcgi.conf;
+ '';
+ };
+ };
+ };
+ })
+ ]);
+}