2020-04-24 23:36:52 +00:00
|
|
|
# We have tests for PCRE and PHP-FPM in nixos/tests/php/ or
|
|
|
|
# both in the same attribute named nixosTests.php
|
|
|
|
|
|
|
|
let
|
|
|
|
generic =
|
2021-06-28 23:13:55 +00:00
|
|
|
{ callPackage
|
|
|
|
, lib
|
|
|
|
, stdenv
|
|
|
|
, nixosTests
|
2021-12-06 16:07:01 +00:00
|
|
|
, tests
|
2021-06-28 23:13:55 +00:00
|
|
|
, fetchurl
|
2023-07-15 17:15:38 +00:00
|
|
|
, makeBinaryWrapper
|
2021-06-28 23:13:55 +00:00
|
|
|
, symlinkJoin
|
|
|
|
, writeText
|
|
|
|
, autoconf
|
|
|
|
, automake
|
|
|
|
, bison
|
|
|
|
, flex
|
|
|
|
, libtool
|
|
|
|
, pkg-config
|
|
|
|
, re2c
|
|
|
|
, apacheHttpd
|
|
|
|
, libargon2
|
|
|
|
, libxml2
|
|
|
|
, pcre2
|
|
|
|
, systemd
|
|
|
|
, system-sendmail
|
|
|
|
, valgrind
|
|
|
|
, xcbuild
|
2023-01-11 07:51:40 +00:00
|
|
|
, writeShellScript
|
|
|
|
, common-updater-scripts
|
|
|
|
, curl
|
|
|
|
, jq
|
2020-05-03 17:38:23 +00:00
|
|
|
|
|
|
|
, version
|
2022-07-14 12:49:19 +00:00
|
|
|
, hash
|
2021-06-28 23:13:55 +00:00
|
|
|
, extraPatches ? [ ]
|
|
|
|
, packageOverrides ? (final: prev: { })
|
2021-12-06 16:07:01 +00:00
|
|
|
, phpAttrsOverrides ? (attrs: { })
|
2020-05-03 17:38:23 +00:00
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
# Sapi flags
|
2020-05-03 17:38:23 +00:00
|
|
|
, cgiSupport ? true
|
|
|
|
, cliSupport ? true
|
|
|
|
, fpmSupport ? true
|
|
|
|
, pearSupport ? true
|
|
|
|
, pharSupport ? true
|
|
|
|
, phpdbgSupport ? true
|
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
# Misc flags
|
2022-11-21 17:40:18 +00:00
|
|
|
, apxs2Support ? false
|
2020-05-03 17:38:23 +00:00
|
|
|
, argon2Support ? true
|
|
|
|
, cgotoSupport ? false
|
|
|
|
, embedSupport ? false
|
|
|
|
, ipv6Support ? true
|
2023-02-02 18:25:31 +00:00
|
|
|
, systemdSupport ? lib.meta.availableOn stdenv.hostPlatform systemd
|
2021-06-28 23:13:55 +00:00
|
|
|
, valgrindSupport ? !stdenv.isDarwin && lib.meta.availableOn stdenv.hostPlatform valgrind
|
2020-05-03 17:38:23 +00:00
|
|
|
, ztsSupport ? apxs2Support
|
|
|
|
}@args:
|
2021-06-28 23:13:55 +00:00
|
|
|
|
|
|
|
let
|
2021-12-06 16:07:01 +00:00
|
|
|
# Compose two functions of the type expected by 'overrideAttrs'
|
|
|
|
# into one where changes made in the first are available to the second.
|
|
|
|
composeOverrides =
|
|
|
|
f: g: attrs:
|
|
|
|
let
|
|
|
|
fApplied = f attrs;
|
|
|
|
attrs' = attrs // fApplied;
|
|
|
|
in
|
|
|
|
fApplied // g attrs';
|
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
# buildEnv wraps php to provide additional extensions and
|
|
|
|
# configuration. Its usage is documented in
|
|
|
|
# doc/languages-frameworks/php.section.md.
|
|
|
|
#
|
|
|
|
# Create a buildEnv with earlier overridden values and
|
|
|
|
# extensions functions in its closure. This is necessary for
|
|
|
|
# consecutive calls to buildEnv and overrides to work as
|
|
|
|
# expected.
|
|
|
|
mkBuildEnv = prevArgs: prevExtensionFunctions: lib.makeOverridable (
|
|
|
|
{ extensions ? ({ enabled, ... }: enabled), extraConfig ? "", ... }@innerArgs:
|
|
|
|
let
|
|
|
|
allArgs = args // prevArgs // innerArgs;
|
|
|
|
filteredArgs = builtins.removeAttrs allArgs [ "extensions" "extraConfig" ];
|
|
|
|
php = generic filteredArgs;
|
|
|
|
|
|
|
|
php-packages = (callPackage ../../../top-level/php-packages.nix {
|
|
|
|
phpPackage = phpWithExtensions;
|
2023-08-22 20:05:09 +00:00
|
|
|
}).overrideScope packageOverrides;
|
2021-06-28 23:13:55 +00:00
|
|
|
|
|
|
|
allExtensionFunctions = prevExtensionFunctions ++ [ extensions ];
|
|
|
|
enabledExtensions =
|
|
|
|
builtins.foldl'
|
|
|
|
(enabled: f:
|
|
|
|
f { inherit enabled; all = php-packages.extensions; })
|
|
|
|
[ ]
|
|
|
|
allExtensionFunctions;
|
|
|
|
|
2022-11-21 17:40:18 +00:00
|
|
|
getExtName = ext: ext.extensionName;
|
2021-06-28 23:13:55 +00:00
|
|
|
|
|
|
|
# Recursively get a list of all internal dependencies
|
|
|
|
# for a list of extensions.
|
|
|
|
getDepsRecursively = extensions:
|
2020-05-03 17:38:23 +00:00
|
|
|
let
|
2021-06-28 23:13:55 +00:00
|
|
|
deps = lib.concatMap
|
|
|
|
(ext: (ext.internalDeps or [ ]) ++ (ext.peclDeps or [ ]))
|
|
|
|
extensions;
|
2020-05-03 17:38:23 +00:00
|
|
|
in
|
2021-06-28 23:13:55 +00:00
|
|
|
if ! (deps == [ ]) then
|
|
|
|
deps ++ (getDepsRecursively deps)
|
|
|
|
else
|
|
|
|
deps;
|
|
|
|
|
|
|
|
# Generate extension load configuration snippets from the
|
|
|
|
# extension parameter. This is an attrset suitable for use
|
|
|
|
# with textClosureList, which is used to put the strings in
|
|
|
|
# the right order - if a plugin which is dependent on
|
|
|
|
# another plugin is placed before its dependency, it will
|
|
|
|
# fail to load.
|
|
|
|
extensionTexts =
|
|
|
|
lib.listToAttrs
|
|
|
|
(map
|
|
|
|
(ext:
|
|
|
|
let
|
|
|
|
extName = getExtName ext;
|
|
|
|
phpDeps = (ext.internalDeps or [ ]) ++ (ext.peclDeps or [ ]);
|
|
|
|
type = "${lib.optionalString (ext.zendExtension or false) "zend_"}extension";
|
|
|
|
in
|
|
|
|
lib.nameValuePair extName {
|
|
|
|
text = "${type}=${ext}/lib/php/extensions/${extName}.so";
|
|
|
|
deps = map getExtName phpDeps;
|
|
|
|
})
|
|
|
|
(enabledExtensions ++ (getDepsRecursively enabledExtensions)));
|
|
|
|
|
|
|
|
extNames = map getExtName enabledExtensions;
|
|
|
|
extraInit = writeText "php-extra-init-${version}.ini" ''
|
|
|
|
${lib.concatStringsSep "\n"
|
|
|
|
(lib.textClosureList extensionTexts extNames)}
|
|
|
|
${extraConfig}
|
2020-05-03 17:38:23 +00:00
|
|
|
'';
|
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
phpWithExtensions = symlinkJoin {
|
|
|
|
name = "php-with-extensions-${version}";
|
|
|
|
inherit (php) version;
|
2023-07-15 17:15:38 +00:00
|
|
|
nativeBuildInputs = [ makeBinaryWrapper ];
|
2021-06-28 23:13:55 +00:00
|
|
|
passthru = php.passthru // {
|
|
|
|
buildEnv = mkBuildEnv allArgs allExtensionFunctions;
|
|
|
|
withExtensions = mkWithExtensions allArgs allExtensionFunctions;
|
2021-12-06 16:07:01 +00:00
|
|
|
overrideAttrs =
|
|
|
|
f:
|
|
|
|
let
|
|
|
|
newPhpAttrsOverrides = composeOverrides (filteredArgs.phpAttrsOverrides or (attrs: { })) f;
|
|
|
|
php = generic (filteredArgs // { phpAttrsOverrides = newPhpAttrsOverrides; });
|
|
|
|
in
|
|
|
|
php.buildEnv { inherit extensions extraConfig; };
|
2021-06-28 23:13:55 +00:00
|
|
|
phpIni = "${phpWithExtensions}/lib/php.ini";
|
|
|
|
unwrapped = php;
|
|
|
|
# Select the right php tests for the php version
|
2021-12-06 16:07:01 +00:00
|
|
|
tests = {
|
|
|
|
nixos = lib.recurseIntoAttrs nixosTests."php${lib.strings.replaceStrings [ "." ] [ "" ] (lib.versions.majorMinor php.version)}";
|
|
|
|
package = tests.php;
|
|
|
|
};
|
2023-10-09 19:29:22 +00:00
|
|
|
inherit (php-packages) extensions buildPecl mkComposerRepository buildComposerProject composerHooks mkExtension;
|
2021-06-28 23:13:55 +00:00
|
|
|
packages = php-packages.tools;
|
|
|
|
meta = php.meta // {
|
|
|
|
outputsToInstall = [ "out" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
paths = [ php ];
|
|
|
|
postBuild = ''
|
|
|
|
ln -s ${extraInit} $out/lib/php.ini
|
|
|
|
|
|
|
|
if test -e $out/bin/php; then
|
2023-04-12 12:48:02 +00:00
|
|
|
wrapProgram $out/bin/php --set-default PHP_INI_SCAN_DIR $out/lib
|
2021-06-28 23:13:55 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if test -e $out/bin/php-fpm; then
|
2023-04-12 12:48:02 +00:00
|
|
|
wrapProgram $out/bin/php-fpm --set-default PHP_INI_SCAN_DIR $out/lib
|
2021-06-28 23:13:55 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if test -e $out/bin/phpdbg; then
|
2023-04-12 12:48:02 +00:00
|
|
|
wrapProgram $out/bin/phpdbg --set-default PHP_INI_SCAN_DIR $out/lib
|
2021-06-28 23:13:55 +00:00
|
|
|
fi
|
2022-04-27 09:35:20 +00:00
|
|
|
|
|
|
|
if test -e $out/bin/php-cgi; then
|
2023-04-12 12:48:02 +00:00
|
|
|
wrapProgram $out/bin/php-cgi --set-default PHP_INI_SCAN_DIR $out/lib
|
2022-04-27 09:35:20 +00:00
|
|
|
fi
|
2021-06-28 23:13:55 +00:00
|
|
|
'';
|
2020-05-03 17:38:23 +00:00
|
|
|
};
|
2021-06-28 23:13:55 +00:00
|
|
|
in
|
|
|
|
phpWithExtensions
|
|
|
|
);
|
|
|
|
|
|
|
|
mkWithExtensions = prevArgs: prevExtensionFunctions: extensions:
|
|
|
|
mkBuildEnv prevArgs prevExtensionFunctions { inherit extensions; };
|
|
|
|
in
|
2021-12-06 16:07:01 +00:00
|
|
|
stdenv.mkDerivation (
|
|
|
|
let
|
|
|
|
attrs = {
|
|
|
|
pname = "php";
|
|
|
|
|
|
|
|
inherit version;
|
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
|
|
|
nativeBuildInputs = [ autoconf automake bison flex libtool pkg-config re2c ]
|
|
|
|
++ lib.optional stdenv.isDarwin xcbuild;
|
|
|
|
|
|
|
|
buildInputs =
|
|
|
|
# PCRE extension
|
|
|
|
[ pcre2 ]
|
|
|
|
|
|
|
|
# Enable sapis
|
2022-10-30 15:09:59 +00:00
|
|
|
++ lib.optionals pearSupport [ libxml2.dev ]
|
2021-12-06 16:07:01 +00:00
|
|
|
|
|
|
|
# Misc deps
|
|
|
|
++ lib.optional apxs2Support apacheHttpd
|
|
|
|
++ lib.optional argon2Support libargon2
|
|
|
|
++ lib.optional systemdSupport systemd
|
|
|
|
++ lib.optional valgrindSupport valgrind
|
|
|
|
;
|
|
|
|
|
|
|
|
CXXFLAGS = lib.optionalString stdenv.cc.isClang "-std=c++11";
|
2021-12-19 01:06:50 +00:00
|
|
|
SKIP_PERF_SENSITIVE = 1;
|
2021-12-06 16:07:01 +00:00
|
|
|
|
|
|
|
configureFlags =
|
|
|
|
# Disable all extensions
|
|
|
|
[ "--disable-all" ]
|
|
|
|
|
|
|
|
# PCRE
|
2022-05-18 14:49:53 +00:00
|
|
|
++ [ "--with-external-pcre=${pcre2.dev}" ]
|
2021-12-06 16:07:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Enable sapis
|
|
|
|
++ lib.optional (!cgiSupport) "--disable-cgi"
|
|
|
|
++ lib.optional (!cliSupport) "--disable-cli"
|
|
|
|
++ lib.optional fpmSupport "--enable-fpm"
|
2022-10-30 15:09:59 +00:00
|
|
|
++ lib.optionals pearSupport [ "--with-pear" "--enable-xml" "--with-libxml" ]
|
2021-12-06 16:07:01 +00:00
|
|
|
++ lib.optional pharSupport "--enable-phar"
|
|
|
|
++ lib.optional (!phpdbgSupport) "--disable-phpdbg"
|
|
|
|
|
|
|
|
|
|
|
|
# Misc flags
|
|
|
|
++ lib.optional apxs2Support "--with-apxs2=${apacheHttpd.dev}/bin/apxs"
|
|
|
|
++ lib.optional argon2Support "--with-password-argon2=${libargon2}"
|
|
|
|
++ lib.optional cgotoSupport "--enable-re2c-cgoto"
|
|
|
|
++ lib.optional embedSupport "--enable-embed"
|
|
|
|
++ lib.optional (!ipv6Support) "--disable-ipv6"
|
|
|
|
++ lib.optional systemdSupport "--with-fpm-systemd"
|
|
|
|
++ lib.optional valgrindSupport "--with-valgrind=${valgrind.dev}"
|
2023-07-15 17:15:38 +00:00
|
|
|
++ lib.optional ztsSupport "--enable-zts"
|
2021-12-06 16:07:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Sendmail
|
|
|
|
++ [ "PROG_SENDMAIL=${system-sendmail}/bin/sendmail" ]
|
|
|
|
;
|
|
|
|
|
|
|
|
hardeningDisable = [ "bindnow" ];
|
|
|
|
|
|
|
|
preConfigure =
|
|
|
|
# Don't record the configure flags since this causes unnecessary
|
|
|
|
# runtime dependencies
|
|
|
|
''
|
|
|
|
for i in main/build-defs.h.in scripts/php-config.in; do
|
|
|
|
substituteInPlace $i \
|
|
|
|
--replace '@CONFIGURE_COMMAND@' '(omitted)' \
|
|
|
|
--replace '@CONFIGURE_OPTIONS@' "" \
|
|
|
|
--replace '@PHP_LDFLAGS@' ""
|
|
|
|
done
|
|
|
|
|
|
|
|
export EXTENSION_DIR=$out/lib/php/extensions
|
2022-05-18 14:49:53 +00:00
|
|
|
|
2021-12-06 16:07:01 +00:00
|
|
|
./buildconf --copy --force
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
if [ -f "scripts/dev/genfiles" ]; then
|
|
|
|
./scripts/dev/genfiles
|
2021-12-06 16:07:01 +00:00
|
|
|
fi
|
|
|
|
'' + lib.optionalString stdenv.isDarwin ''
|
|
|
|
substituteInPlace configure --replace "-lstdc++" "-lc++"
|
|
|
|
'';
|
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
test -d $out/etc || mkdir $out/etc
|
|
|
|
cp php.ini-production $out/etc/php.ini
|
|
|
|
'';
|
|
|
|
|
|
|
|
postFixup = ''
|
|
|
|
mkdir -p $dev/bin $dev/share/man/man1
|
|
|
|
mv $out/bin/phpize $out/bin/php-config $dev/bin/
|
|
|
|
mv $out/share/man/man1/phpize.1.gz \
|
|
|
|
$out/share/man/man1/php-config.1.gz \
|
|
|
|
$dev/share/man/man1/
|
|
|
|
'';
|
|
|
|
|
|
|
|
src = fetchurl {
|
|
|
|
url = "https://www.php.net/distributions/php-${version}.tar.bz2";
|
2022-07-14 12:49:19 +00:00
|
|
|
inherit hash;
|
2021-12-06 16:07:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
patches = [ ./fix-paths-php7.patch ] ++ extraPatches;
|
|
|
|
|
|
|
|
separateDebugInfo = true;
|
|
|
|
|
|
|
|
outputs = [ "out" "dev" ];
|
|
|
|
|
|
|
|
passthru = {
|
2023-01-11 07:51:40 +00:00
|
|
|
updateScript =
|
|
|
|
let
|
|
|
|
script = writeShellScript "php${lib.versions.major version}${lib.versions.minor version}-update-script" ''
|
|
|
|
set -o errexit
|
|
|
|
PATH=${lib.makeBinPath [ common-updater-scripts curl jq ]}
|
|
|
|
new_version=$(curl --silent "https://www.php.net/releases/active" | jq --raw-output '."${lib.versions.major version}"."${lib.versions.majorMinor version}".version')
|
|
|
|
update-source-version "$UPDATE_NIX_ATTR_PATH.unwrapped" "$new_version" "--file=$1"
|
|
|
|
'';
|
|
|
|
in [
|
|
|
|
script
|
|
|
|
# Passed as an argument so that update.nix can ensure it does not become a store path.
|
|
|
|
(./. + "/${lib.versions.majorMinor version}.nix")
|
|
|
|
];
|
2021-12-06 16:07:01 +00:00
|
|
|
buildEnv = mkBuildEnv { } [ ];
|
|
|
|
withExtensions = mkWithExtensions { } [ ];
|
|
|
|
overrideAttrs =
|
|
|
|
f:
|
|
|
|
let
|
|
|
|
newPhpAttrsOverrides = composeOverrides phpAttrsOverrides f;
|
|
|
|
php = generic (args // { phpAttrsOverrides = newPhpAttrsOverrides; });
|
|
|
|
in
|
|
|
|
php;
|
|
|
|
inherit ztsSupport;
|
|
|
|
};
|
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
description = "An HTML-embedded scripting language";
|
|
|
|
homepage = "https://www.php.net/";
|
|
|
|
license = licenses.php301;
|
2023-02-16 17:41:37 +00:00
|
|
|
mainProgram = "php";
|
2021-12-06 16:07:01 +00:00
|
|
|
maintainers = teams.php.members;
|
|
|
|
platforms = platforms.all;
|
|
|
|
outputsToInstall = [ "out" "dev" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
attrs // phpAttrsOverrides attrs
|
|
|
|
);
|
2021-06-28 23:13:55 +00:00
|
|
|
in
|
|
|
|
generic
|