-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
171 lines (159 loc) · 4.53 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
{
description = "php-defer";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
flake-utils = {
url = "github:numtide/flake-utils";
};
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.flake-utils.follows = "flake-utils";
inputs.gitignore.follows = "gitignore";
};
ext-ast = {
url = "github:nikic/php-ast";
flake = false;
};
ext-vyrtue = {
url = "github:jbboehr/php-vyrtue";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
self,
nixpkgs,
flake-utils,
gitignore,
pre-commit-hooks,
ext-ast,
ext-vyrtue,
} @ args:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = nixpkgs.legacyPackages.${system};
lib = pkgs.lib;
src' = gitignore.lib.gitignoreSource ./.;
src = pkgs.lib.cleanSourceWith {
name = "php-defer-source";
src = src';
filter = gitignore.lib.gitignoreFilterWith {
basePath = ./.;
extraRules = ''
.clang-format
composer.json
composer.lock
.editorconfig
.envrc
.gitattributes
.github
.gitignore
*.md
*.nix
flake.*
'';
};
};
makePhp = {
php,
vyrtue,
}:
php.buildEnv {
extraConfig = ''
include_path = .:${ext-ast}/
'';
extensions = {
enabled,
all,
}:
enabled ++ [all.ast all.opcache vyrtue];
};
makePackage = {
php,
vyrtue,
}:
pkgs.callPackage ./derivation.nix {
php = makePhp {
inherit php vyrtue;
};
inherit (php) buildPecl;
inherit src vyrtue;
};
makeCheck = package:
package.overrideAttrs (old: {
doCheck = true;
});
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = src';
hooks = {
actionlint.enable = true;
alejandra.enable = true;
alejandra.excludes = ["\/vendor\/"];
clang-format.enable = true;
clang-format.types_or = ["c" "c++"];
clang-format.files = "\\.(c|h)$";
markdownlint.enable = true;
markdownlint.excludes = ["LICENSE\.md"];
shellcheck.enable = true;
};
};
mkDevShell = package:
pkgs.mkShell {
inputsFrom = [package];
buildInputs = with pkgs; [
actionlint
clang-tools
lcov
gdb
package.php
package.php.packages.composer
valgrind
];
shellHook = ''
${pre-commit-check.shellHook}
#ln -sf ${package.php.unwrapped.dev}/include/php/ .direnv/php-include
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}'
'';
};
in rec {
packages = rec {
php81 = makePackage {
php = pkgs.php81;
vyrtue = ext-vyrtue.packages.${system}.php81;
};
php82 = makePackage {
php = pkgs.php82;
vyrtue = ext-vyrtue.packages.${system}.php82;
};
php83 = makePackage {
php = pkgs.php83;
vyrtue = ext-vyrtue.packages.${system}.php83;
};
default = php81;
};
devShells = rec {
php81 = mkDevShell packages.php81;
php82 = mkDevShell packages.php82;
php83 = mkDevShell packages.php83;
default = php81;
};
checks = {
inherit pre-commit-check;
php81 = makeCheck packages.php81;
php82 = makeCheck packages.php82;
php83 = makeCheck packages.php83;
};
formatter = pkgs.alejandra;
}
);
}