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