level0.nix (1832B)
1 { 2 config, 3 lib, 4 pkgs, 5 ... 6 }: 7 8 with lib; 9 10 let 11 cfg = config.services.level0; 12 in 13 { 14 options.services.level0 = { 15 enable = mkEnableOption "level0"; 16 package = mkPackageOption pkgs "level0" { }; 17 nginx = mkOption { 18 default = { }; 19 description = '' 20 Configuration for nginx reverse proxy. 21 ''; 22 type = types.submodule { 23 options = { 24 enable = mkOption { 25 type = types.bool; 26 default = false; 27 description = '' 28 Configure the nginx reverse proxy settings. 29 ''; 30 }; 31 hostName = mkOption { 32 type = types.str; 33 description = '' 34 The hostname use to setup the virtualhost configuration 35 ''; 36 }; 37 }; 38 }; 39 }; 40 }; 41 42 config = mkIf cfg.enable (mkMerge [ 43 { 44 services.phpfpm.pools.level0 = { 45 user = "nobody"; 46 settings = { 47 "pm" = "dynamic"; 48 "listen.owner" = config.services.nginx.user; 49 "pm.max_children" = 5; 50 "pm.start_servers" = 2; 51 "pm.min_spare_servers" = 1; 52 "pm.max_spare_servers" = 3; 53 "pm.max_requests" = 500; 54 "security.limit_extensions" = ".php .js"; 55 }; 56 }; 57 } 58 (mkIf cfg.nginx.enable { 59 services.nginx = { 60 enable = true; 61 virtualHosts."${cfg.nginx.hostName}" = { 62 locations."/" = { 63 root = "${cfg.package}/share/php/level0/www"; 64 extraConfig = '' 65 fastcgi_split_path_info ^(.+\.php)(/.+)$; 66 fastcgi_pass unix:${config.services.phpfpm.pools.level0.socket}; 67 fastcgi_index index.php; 68 include ${config.services.nginx.package}/conf/fastcgi.conf; 69 ''; 70 }; 71 }; 72 }; 73 }) 74 ]); 75 }