-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
324 lines (306 loc) · 10.1 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# Copyright (c) anno Domini nostri Jesu Christi MMXVI-MMXXIV John Boehr & contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
{
description = "php-perfidious";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
systems.url = "github:nix-systems/default-linux";
flake-utils = {
url = "github:numtide/flake-utils";
inputs.systems.follows = "systems";
};
gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.nixpkgs-stable.follows = "nixpkgs";
inputs.gitignore.follows = "gitignore";
};
nix-github-actions = {
url = "github:nix-community/nix-github-actions";
inputs.nixpkgs.follows = "nixpkgs";
};
libpfm4-unstable-src = {
url = "git+https://git.code.sf.net/p/perfmon2/libpfm4";
flake = false;
};
};
outputs = {
self,
nixpkgs,
nixpkgs-unstable,
systems,
flake-utils,
gitignore,
pre-commit-hooks,
nix-github-actions,
libpfm4-unstable-src,
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = nixpkgs.legacyPackages.${system};
pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
lib = pkgs.lib;
src' = gitignore.lib.gitignoreSource ./.;
iwyu = pkgs.callPackage ./nix/iwyu.nix {};
libpfm-unstable = pkgs.libpfm.overrideAttrs (o: {
version = "${o.version}+git-master";
src = libpfm4-unstable-src;
});
src = pkgs.lib.cleanSourceWith {
name = "php-perfidious-source";
src = src';
filter = gitignore.lib.gitignoreFilterWith {
basePath = ./.;
extraRules = ''
.clang-format
composer.json
composer.lock
.editorconfig
.envrc
.gitattributes
.github
.gitignore
*.md
*.nix
flake.*
'';
};
};
makePackage = {
stdenv ? pkgs.stdenv,
php ? pkgs.php,
libpfm ? pkgs.libpfm,
debugSupport ? false,
coverageSupport ? false,
}:
pkgs.callPackage ./nix/derivation.nix {
inherit src;
inherit stdenv php libpfm;
inherit debugSupport coverageSupport;
buildPecl = pkgs.callPackage (nixpkgs + "/pkgs/build-support/php/build-pecl.nix") {
inherit php stdenv;
};
};
makeCheck = package:
package.override {
checkSupport = true;
WerrorSupport = true;
};
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = src';
hooks = {
actionlint.enable = true;
alejandra.enable = true;
alejandra.excludes = ["\/vendor\/"];
# I hate formatters
#clang-format.enable = true;
#clang-format.types_or = ["c" "c++"];
#clang-format.files = "\\.(c|h)$";
markdownlint.enable = true;
markdownlint.excludes = ["LICENSE\.md"];
markdownlint.settings.configuration = {
MD013 = {
line_length = 1488;
# this doesn't seem to work
table = false;
};
};
shellcheck.enable = true;
};
};
makeDevShell = package:
(pkgs.mkShell.override {
stdenv = package.stdenv;
}) {
inputsFrom = [package];
buildInputs = with pkgs; [
actionlint
autoconf-archive
clang-tools
iwyu
lcov
linuxPackages_latest.perf
gdb
package.php.packages.composer
valgrind
];
shellHook = ''
${pre-commit-check.shellHook}
mkdir -p .direnv/include
unlink .direnv/include/php
ln -sf ${package.php.unwrapped.dev}/include/php/ .direnv/include/php
unlink .direnv/include/perfmon
ln -sf ${package.libpfm}/include/perfmon .direnv/include/perfmon
export REPORT_EXIT_STATUS=1
export NO_INTERACTION=1
export PATH="$PWD/vendor/bin:$PATH"
# opcache isn't getting loaded for tests because tests are run with '-n' and nixos doesn't compile
# in opcache and relies on mkWrapper to load extensions
export TEST_PHP_ARGS='-c ${package.php.phpIni}'
# php.unwrapped from the buildDeps is overwriting php
export PATH="${package.php}/bin:./vendor/bin:$PATH"
'';
};
makeVmCheck = package: let
php = package.php.buildEnv {
extensions = {
enabled,
all,
}:
enabled ++ [all.opcache package];
};
in
pkgs.testers.runNixOSTest {
name = "php-perfidious-vm-test";
qemu.package = pkgs.qemu_full;
nodes = {
machine1 = {
config,
pkgs,
...
}: {
virtualisation.qemu.options = ["-cpu host"];
boot.kernel.sysctl."kernel.perf_event_paranoid" = -1;
boot.kernel.sysctl."kernel.kptr_restrict" = lib.mkForce 0;
environment.systemPackages = [
php
];
};
};
testScript = {nodes, ...}: ''
machine.wait_for_unit("default.target")
machine.succeed("php -m && php -m | grep -i perfidious")
machine.succeed("cp -r --no-preserve=mode,ownership ${src}/* .")
machine.succeed("cp --no-preserve=mode,ownership ${php.unwrapped}/lib/build/run-tests.php .")
machine.succeed("TEST_PHP_DETAILED=1 NO_INTERACTION=1 REPORT_EXIT_STATUS=1 php run-tests.php || (find tests -name '*.log' | xargs -n1 cat ; exit 1)")
'';
};
matrix = with pkgs; {
php = {
inherit php81 php82 php83;
php84 = pkgs-unstable.php84;
};
stdenv = {
gcc = stdenv;
clang = clangStdenv;
musl = pkgsMusl.stdenv;
};
libpfm = {
inherit libpfm libpfm-unstable;
};
};
# @see https://github.com/NixOS/nixpkgs/pull/110787
buildConfs =
(lib.cartesianProductOfSets {
php = ["php81" "php82" "php83" "php84"];
stdenv = [
"gcc"
"clang"
# totally broken
# "musl"
];
libpfm = ["libpfm" "libpfm-unstable"];
coverageSupport = [false];
})
++ [
{
php = "php81";
stdenv = "gcc";
libpfm = "libpfm";
debugSupport = true;
}
]
++ (lib.cartesianProductOfSets {
php = ["php81" "php82" "php83" "php84"];
stdenv = ["gcc"];
libpfm = ["libpfm"];
debugSupport = [false true];
coverageSupport = [true];
});
buildFn = {
php,
libpfm,
stdenv,
debugSupport ? false,
coverageSupport ? false,
}:
lib.nameValuePair
(lib.concatStringsSep "-" (lib.filter (v: v != "") [
"${php}"
"${stdenv}"
#(if stdenv == "gcc" then "" else "${stdenv}")
(
if libpfm == "libpfm"
then ""
else "${libpfm}"
)
(
if debugSupport
then "debug"
else ""
)
(
if coverageSupport
then "coverage"
else ""
)
]))
(
makePackage {
php = matrix.php.${php};
libpfm = matrix.libpfm.${libpfm};
stdenv = matrix.stdenv.${stdenv};
inherit debugSupport coverageSupport;
}
);
packages' = builtins.listToAttrs (builtins.map buildFn buildConfs);
packages =
packages'
// {
# php81 = packages.php81-gcc;
# php82 = packages.php82-gcc;
# php83 = packages.php83-gcc;
# php84 = packages.php84-gcc;
default = packages.php81-gcc;
};
in {
inherit packages;
devShells = builtins.mapAttrs (name: package: makeDevShell package) packages;
checks =
{inherit pre-commit-check;}
// (builtins.mapAttrs (name: package: makeCheck package) packages)
// (lib.mapAttrs' (name: value: lib.nameValuePair (name + "-vmtest") (makeVmCheck value)) packages);
formatter = pkgs.alejandra;
}
)
// {
# prolly gonna break at some point
githubActions.matrix.include = let
cleanFn = v: v // {name = builtins.replaceStrings ["githubActions." "checks." "x86_64-linux."] ["" "" ""] v.attr;};
in
builtins.map cleanFn
(nix-github-actions.lib.mkGithubMatrix {
attrPrefix = "checks";
checks = nixpkgs.lib.getAttrs ["x86_64-linux"] self.checks;
})
.matrix
.include;
};
}