lol

php.services.default: init

+266
+1
nixos/modules/misc/documentation/modular-services.nix
··· 21 21 _file = "${__curPos.file}:${toString __curPos.line}"; 22 22 options = { 23 23 "<imports = [ pkgs.ghostunnel.services.default ]>" = fakeSubmodule pkgs.ghostunnel.services.default; 24 + "<imports = [ pkgs.php.services.default ]>" = fakeSubmodule pkgs.php.services.default; 24 25 }; 25 26 }; 26 27 in
+4
nixos/tests/php/default.nix
··· 13 13 imports = [ ./fpm.nix ]; 14 14 _module.args.php = php'; 15 15 }; 16 + fpm-modular = runTest { 17 + imports = [ ./fpm-modular.nix ]; 18 + _module.args.php = php'; 19 + }; 16 20 httpd = runTest { 17 21 imports = [ ./httpd.nix ]; 18 22 _module.args.php = php';
+71
nixos/tests/php/fpm-modular.nix
··· 1 + { lib, php, ... }: 2 + { 3 + name = "php-${php.version}-fpm-modular-nginx-test"; 4 + meta.maintainers = with lib.maintainers; [ 5 + aanderse 6 + ]; 7 + 8 + nodes.machine = 9 + { config, pkgs, ... }: 10 + { 11 + environment.systemPackages = [ php ]; 12 + 13 + services.nginx = { 14 + enable = true; 15 + 16 + virtualHosts."phpfpm" = 17 + let 18 + testdir = pkgs.writeTextDir "web/index.php" "<?php phpinfo();"; 19 + in 20 + { 21 + root = "${testdir}/web"; 22 + locations."~ \\.php$".extraConfig = '' 23 + fastcgi_pass unix:${config.system.services.php-fpm.php-fpm.settings.foobar.listen}; 24 + fastcgi_index index.php; 25 + include ${config.services.nginx.package}/conf/fastcgi_params; 26 + include ${pkgs.nginx}/conf/fastcgi.conf; 27 + ''; 28 + locations."/" = { 29 + tryFiles = "$uri $uri/ index.php"; 30 + index = "index.php index.html index.htm"; 31 + }; 32 + }; 33 + }; 34 + 35 + system.services.php-fpm = { 36 + imports = [ php.services.default ]; 37 + php-fpm = { 38 + package = php; 39 + settings = { 40 + foobar = { 41 + "user" = "nginx"; 42 + "listen.group" = "nginx"; 43 + "listen.mode" = "0600"; 44 + "listen.owner" = "nginx"; 45 + "pm" = "dynamic"; 46 + "pm.max_children" = 5; 47 + "pm.max_requests" = 500; 48 + "pm.max_spare_servers" = 3; 49 + "pm.min_spare_servers" = 1; 50 + "pm.start_servers" = 2; 51 + }; 52 + }; 53 + }; 54 + }; 55 + }; 56 + testScript = 57 + { ... }: 58 + '' 59 + machine.wait_for_unit("nginx.service") 60 + machine.wait_for_unit("php-fpm.service") 61 + 62 + # Check so we get an evaluated PHP back 63 + response = machine.succeed("curl -fvvv -s http://127.0.0.1:80/") 64 + assert "PHP Version ${php.version}" in response, "PHP version not detected" 65 + 66 + # Check so we have database and some other extensions loaded 67 + for ext in ["json", "opcache", "pdo_mysql", "pdo_pgsql", "pdo_sqlite", "apcu"]: 68 + assert ext in response, f"Missing {ext} extension" 69 + machine.succeed(f'test -n "$(php -m | grep -i {ext})"') 70 + ''; 71 + }
+4
pkgs/development/interpreters/php/generic.nix
··· 387 387 in 388 388 php; 389 389 inherit ztsSupport; 390 + 391 + services.default = { 392 + imports = [ ./service.nix ]; 393 + }; 390 394 }; 391 395 392 396 meta = with lib; {
+186
pkgs/development/interpreters/php/service.nix
··· 1 + { 2 + options, 3 + config, 4 + pkgs, 5 + lib, 6 + ... 7 + }: 8 + let 9 + cfg = config.php-fpm; 10 + format = pkgs.formats.iniWithGlobalSection { }; 11 + configFile = format.generate "php-fpm.conf" { 12 + globalSection = lib.filterAttrs (_: v: !lib.isAttrs v) cfg.settings; 13 + sections = lib.filterAttrs (_: lib.isAttrs) cfg.settings; 14 + }; 15 + 16 + poolOpts = 17 + { name, ... }: 18 + { 19 + freeformType = 20 + with lib.types; 21 + attrsOf (oneOf [ 22 + str 23 + int 24 + bool 25 + ]); 26 + options = { 27 + listen = lib.mkOption { 28 + type = 29 + with lib.types; 30 + oneOf [ 31 + path 32 + port 33 + str 34 + ]; 35 + default = "/run/php-fpm/${name}.sock"; 36 + description = '' 37 + The address on which to accept FastCGI requests. Valid syntaxes are: `ip.add.re.ss:port`, `port`, `/path/to/unix/socket`. 38 + ''; 39 + }; 40 + 41 + pm = lib.mkOption { 42 + type = lib.types.enum [ 43 + "static" 44 + "ondemand" 45 + "dynamic" 46 + ]; 47 + description = '' 48 + Choose how the process manager will control the number of child processes. 49 + 50 + `static` - the number of child processes is fixed (`pm.max_children`). 51 + `ondemand` - the processes spawn on demand (when requested, as opposed to `dynamic`, where `pm.start_servers` are started when the service is started). 52 + `dynamic` - the number of child processes is set dynamically based on the following directives: `pm.max_children`, `pm.start_servers`, pm.min_spare_servers, `pm.max_spare_servers`. 53 + ''; 54 + }; 55 + 56 + "pm.max_children" = lib.mkOption { 57 + type = lib.types.int; 58 + description = '' 59 + The number of child processes to be created when `pm` is set to `static` and the maximum 60 + number of child processes to be created when `pm` is set to `dynamic`. 61 + 62 + This option sets the limit on the number of simultaneous requests that will be served. 63 + ''; 64 + }; 65 + 66 + user = lib.mkOption { 67 + type = lib.types.str; 68 + description = '' 69 + Unix user of FPM processes. 70 + ''; 71 + }; 72 + }; 73 + }; 74 + in 75 + { 76 + _class = "service"; 77 + 78 + options.php-fpm = { 79 + package = lib.mkPackageOption pkgs "php" { 80 + example = '' 81 + php.buildEnv { 82 + extensions = 83 + { all, ... }: 84 + with all; 85 + [ 86 + imagick 87 + opcache 88 + ]; 89 + extraConfig = "memory_limit=256M"; 90 + } 91 + ''; 92 + }; 93 + 94 + settings = lib.mkOption { 95 + type = lib.types.submodule { 96 + freeformType = 97 + with lib.types; 98 + attrsOf (oneOf [ 99 + str 100 + int 101 + bool 102 + (submodule poolOpts) 103 + ]); 104 + options = { 105 + log_level = lib.mkOption { 106 + type = lib.types.enum [ 107 + "alert" 108 + "error" 109 + "warning" 110 + "notice" 111 + "debug" 112 + ]; 113 + default = "notice"; 114 + description = '' 115 + Error log level. 116 + ''; 117 + }; 118 + }; 119 + }; 120 + default = { }; 121 + example = lib.literalExpression '' 122 + { 123 + log_level = "debug"; 124 + log_limit = 2048; 125 + 126 + mypool = { 127 + "user" = "php"; 128 + "group" = "php"; 129 + "listen.owner" = "caddy"; 130 + "listen.group" = "caddy"; 131 + "pm" = "dynamic"; 132 + "pm.max_children" = 75; 133 + "pm.start_servers" = 10; 134 + "pm.min_spare_servers" = 5; 135 + "pm.max_spare_servers" = 20; 136 + "pm.max_requests" = 500; 137 + } 138 + } 139 + ''; 140 + description = '' 141 + PHP FPM configuration. Refer to [upstream documentation](https://www.php.net/manual/en/install.fpm.configuration.php) for details on supported values. 142 + ''; 143 + }; 144 + }; 145 + 146 + config = { 147 + php-fpm.settings = { 148 + error_log = "syslog"; 149 + daemonize = false; 150 + }; 151 + 152 + process.argv = [ 153 + "${cfg.package}/bin/php-fpm" 154 + "-y" 155 + configFile 156 + ]; 157 + } 158 + // lib.optionalAttrs (options ? systemd) { 159 + 160 + systemd.service = { 161 + after = [ "network.target" ]; 162 + documentation = [ "man:php-fpm(8)" ]; 163 + 164 + serviceConfig = { 165 + Type = "notify"; 166 + ExecReload = "${pkgs.coreutils}/bin/kill -USR2 $MAINPID"; 167 + RuntimeDirectory = "php-fpm"; 168 + RuntimeDirectoryPreserve = true; 169 + Restart = "always"; 170 + }; 171 + }; 172 + 173 + } 174 + // lib.optionalAttrs (options ? finit) { 175 + 176 + finit.service = { 177 + conditions = [ "service/syslogd/ready" ]; 178 + reload = "${pkgs.coreutils}/bin/kill -USR2 $MAINPID"; 179 + notify = "systemd"; 180 + }; 181 + }; 182 + 183 + meta.maintainers = with lib.maintainers; [ 184 + aanderse 185 + ]; 186 + }