blob: c203bc026fce630f10a697b8c497eccbcee8d85d (
plain)
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
|
{
lib,
php,
runCommand,
stdenv,
stdenvAdapters,
}:
let
runTest =
name: body:
runCommand name { } ''
testFailed=
checking() {
echo -n "Checking $1... " > /dev/stderr
}
ok() {
echo ok > /dev/stderr
}
nok() {
echo fail > /dev/stderr
testFailed=1
}
${body}
if test -n "$testFailed"; then
exit 1
fi
touch $out
'';
check = cond: if cond then "ok" else "nok";
in
{
withExtensions-enables-previously-disabled-extensions = runTest "php-test-withExtensions-enables-previously-disabled-extensions" ''
php="${php}"
checking "that imagick is not present by default"
$php/bin/php -r 'exit(extension_loaded("imagick") ? 1 : 0);' && ok || nok
phpWithImagick="${php.withExtensions ({ all, ... }: [ all.imagick ])}"
checking "that imagick extension is present when enabled"
$phpWithImagick/bin/php -r 'exit(extension_loaded("imagick") ? 0 : 1);' && ok || nok
'';
overrideAttrs-preserves-enabled-extensions =
let
customPhp = (php.withExtensions ({ all, ... }: [ all.imagick ])).overrideAttrs (attrs: {
postInstall = attrs.postInstall or "" + ''
touch "$out/oApee-was-here"
'';
});
in
runTest "php-test-overrideAttrs-preserves-enabled-extensions" ''
php="${customPhp}"
phpUnwrapped="${customPhp.unwrapped}"
checking "if overrides took hold"
test -f "$phpUnwrapped/oApee-was-here" && ok || nok
checking "if imagick extension is still present"
$php/bin/php -r 'exit(extension_loaded("imagick") ? 0 : 1);' && ok || nok
checking "if imagick extension is linked against the overridden PHP"
echo $php
$php/bin/php -r 'exit(extension_loaded("imagick") ? 0 : 1);' && ok || nok
'';
unwrapped-overrideAttrs-stacks =
let
customPhp = lib.pipe php.unwrapped [
(
pkg:
pkg.overrideAttrs (attrs: {
postInstall = attrs.postInstall or "" + ''
touch "$out/oAs-first"
'';
})
)
(
pkg:
pkg.overrideAttrs (attrs: {
postInstall = attrs.postInstall or "" + ''
touch "$out/oAs-second"
'';
})
)
];
in
runTest "php-test-unwrapped-overrideAttrs-stacks" ''
checking "if first override remained"
${check (builtins.match ".*oAs-first.*" customPhp.postInstall != null)}
checking "if second override is there"
${check (builtins.match ".*oAs-second.*" customPhp.postInstall != null)}
'';
# Regression test for https://github.com/NixOS/nixpkgs/issues/509863:
# wrapping php's stdenv with an adapter that uses `extendMkDerivationArgs`
# (e.g. `keepDebugInfo`) used to trigger an infinite recursion via the
# custom `passthru.overrideAttrs` defined for unwrapped php. Forcing the
# derivation here would stack-overflow before the fix; checking
# `dontStrip` also confirms the adapter actually applied.
stdenvAdapter-keepDebugInfo-does-not-recurse =
let
customPhp = php.override {
stdenv = stdenvAdapters.keepDebugInfo stdenv;
};
in
runTest "php-test-stdenvAdapter-keepDebugInfo-does-not-recurse" ''
checking "if the override evaluates without infinite recursion"
${check (builtins.isString customPhp.unwrapped.drvPath)}
checking "if keepDebugInfo's dontStrip propagated to the unwrapped derivation"
${check (customPhp.unwrapped.dontStrip or false)}
'';
wrapped-overrideAttrs-stacks =
let
customPhp = lib.pipe php [
(
pkg:
pkg.overrideAttrs (attrs: {
postInstall = attrs.postInstall or "" + ''
touch "$out/oAs-first"
'';
})
)
(
pkg:
pkg.overrideAttrs (attrs: {
postInstall = attrs.postInstall or "" + ''
touch "$out/oAs-second"
'';
})
)
];
in
runTest "php-test-wrapped-overrideAttrs-stacks" ''
checking "if first override remained"
${check (builtins.match ".*oAs-first.*" customPhp.unwrapped.postInstall != null)}
checking "if second override is there"
${check (builtins.match ".*oAs-second.*" customPhp.unwrapped.postInstall != null)}
'';
}
|