-
Notifications
You must be signed in to change notification settings - Fork 32
/
flake.nix
233 lines (218 loc) · 6.85 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
{
description = "php-psr";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
systems.url = "github:nix-systems/default";
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";
};
};
outputs = {
self,
nixpkgs,
nixpkgs-unstable,
systems,
flake-utils,
gitignore,
pre-commit-hooks,
nix-github-actions,
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = nixpkgs.legacyPackages.${system};
pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
inherit (pkgs) lib;
src' = gitignore.lib.gitignoreSource ./.;
src = pkgs.lib.cleanSourceWith {
name = "php-psr-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,
debugSupport ? false,
coverageSupport ? false,
}:
pkgs.callPackage ./nix/derivation.nix {
inherit src;
inherit stdenv php;
#inherit debugSupport coverageSupport;
buildPecl = pkgs.callPackage (nixpkgs + "/pkgs/build-support/php/build-pecl.nix") {
inherit php stdenv;
};
};
makeCheck = package:
package.override {
checkSupport = true;
};
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = src';
hooks = {
actionlint.enable = true;
actionlint.excludes = ["^.github\/workflows\/windows.yml"];
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;
# @TODO FIXME
shellcheck.excludes = ["^.github\/scripts\/"];
};
};
makeDevShell = package:
(pkgs.mkShell.override {
stdenv = package.stdenv;
}) {
inputsFrom = [package];
buildInputs = with pkgs; [
actionlint
autoconf-archive
clang-tools
lcov
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
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"
'';
};
matrix = with pkgs; {
php = {
inherit php81 php82 php83;
php84 = pkgs-unstable.php84;
};
stdenv = {
gcc = stdenv;
clang = clangStdenv;
musl = pkgsMusl.stdenv;
};
};
# @see https://github.com/NixOS/nixpkgs/pull/110787
buildConfs =
(lib.cartesianProductOfSets {
php = ["php81" "php82" "php83" "php84"];
stdenv = [
"gcc"
"clang"
# totally broken
# "musl"
];
coverageSupport = [false];
})
++ (lib.cartesianProductOfSets {
php = ["php81" "php82" "php83" "php84"];
stdenv = ["gcc"];
coverageSupport = [true];
});
buildFn = {
php,
stdenv,
coverageSupport ? false,
}:
lib.nameValuePair
(lib.concatStringsSep "-" (lib.filter (v: v != "") [
"${php}"
"${stdenv}"
#(if stdenv == "gcc" then "" else "${stdenv}")
(
if coverageSupport
then "coverage"
else ""
)
]))
(
makePackage {
php = matrix.php.${php};
stdenv = matrix.stdenv.${stdenv};
inherit 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;
php-psr = packages.php81-gcc;
};
in rec {
inherit packages;
devShells = builtins.mapAttrs (name: package: makeDevShell package) packages;
checks =
{inherit pre-commit-check;}
// (builtins.mapAttrs (name: package: makeCheck package) 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;
};
}