3
0
Fork 0
forked from mirrors/nixpkgs

php: Simplify generic.nix

There is no need for the outer function since all arguments are shadowed anyway.
This commit is contained in:
Jan Tojnar 2021-06-06 08:33:46 +02:00
parent 4a34590ece
commit c27d583b42
No known key found for this signature in database
GPG key ID: 7FAB2A15F7A607A4
3 changed files with 214 additions and 219 deletions

View file

@ -1,9 +1,7 @@
{ callPackage, lib, stdenv, nixosTests, ... }@_args: { callPackage, lib, stdenv, ... }@_args:
let let
generic = (import ./generic.nix) _args; base = callPackage ./generic.nix (_args // {
base = callPackage generic (_args // {
version = "7.4.20"; version = "7.4.20";
sha256 = "0d5ncz97y0271dsmz269wl4721vhq2fn6pmm9rxglc756p36pnha"; sha256 = "0d5ncz97y0271dsmz269wl4721vhq2fn6pmm9rxglc756p36pnha";
}); });

View file

@ -1,9 +1,7 @@
{ callPackage, lib, stdenv, nixosTests, ... }@_args: { callPackage, lib, stdenv, ... }@_args:
let let
generic = (import ./generic.nix) _args; base = callPackage ./generic.nix (_args // {
base = callPackage generic (_args // {
version = "8.0.7"; version = "8.0.7";
sha256 = "0yazcc9x66xg1gmi3rpgk891g6s3mm7aywcadqfqnx1mdz4z5ckj"; sha256 = "0yazcc9x66xg1gmi3rpgk891g6s3mm7aywcadqfqnx1mdz4z5ckj";
}); });

View file

@ -1,8 +1,6 @@
# We have tests for PCRE and PHP-FPM in nixos/tests/php/ or # We have tests for PCRE and PHP-FPM in nixos/tests/php/ or
# both in the same attribute named nixosTests.php # both in the same attribute named nixosTests.php
{ callPackage, lib, stdenv, nixosTests, ... }:
let let
generic = generic =
{ callPackage, lib, stdenv, nixosTests, fetchurl, makeWrapper { callPackage, lib, stdenv, nixosTests, fetchurl, makeWrapper
@ -33,250 +31,251 @@ let
, valgrindSupport ? !stdenv.isDarwin , valgrindSupport ? !stdenv.isDarwin
, ztsSupport ? apxs2Support , ztsSupport ? apxs2Support
}@args: }@args:
let
# 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 { let
phpPackage = phpWithExtensions; # buildEnv wraps php to provide additional extensions and
}).overrideScope' packageOverrides; # 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;
allExtensionFunctions = prevExtensionFunctions ++ [ extensions ]; php-packages = (callPackage ../../../top-level/php-packages.nix {
enabledExtensions = phpPackage = phpWithExtensions;
builtins.foldl' }).overrideScope' packageOverrides;
(enabled: f:
f { inherit enabled; all = php-packages.extensions; })
[]
allExtensionFunctions;
getExtName = ext: lib.removePrefix "php-" (builtins.parseDrvName ext.name).name; allExtensionFunctions = prevExtensionFunctions ++ [ extensions ];
enabledExtensions =
builtins.foldl'
(enabled: f:
f { inherit enabled; all = php-packages.extensions; })
[]
allExtensionFunctions;
# Recursively get a list of all internal dependencies getExtName = ext: lib.removePrefix "php-" (builtins.parseDrvName ext.name).name;
# for a list of extensions.
getDepsRecursively = extensions:
let
deps = lib.concatMap
(ext: (ext.internalDeps or []) ++ (ext.peclDeps or []))
extensions;
in
if ! (deps == []) then
deps ++ (getDepsRecursively deps)
else
deps;
# Generate extension load configuration snippets from the # Recursively get a list of all internal dependencies
# extension parameter. This is an attrset suitable for use # for a list of extensions.
# with textClosureList, which is used to put the strings in getDepsRecursively = extensions:
# the right order - if a plugin which is dependent on let
# another plugin is placed before its dependency, it will deps = lib.concatMap
# fail to load. (ext: (ext.internalDeps or []) ++ (ext.peclDeps or []))
extensionTexts = extensions;
lib.listToAttrs in
(map (ext: if ! (deps == []) then
let deps ++ (getDepsRecursively deps)
extName = getExtName ext; else
phpDeps = (ext.internalDeps or []) ++ (ext.peclDeps or []); deps;
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; # Generate extension load configuration snippets from the
extraInit = writeText "php-extra-init-${version}.ini" '' # extension parameter. This is an attrset suitable for use
${lib.concatStringsSep "\n" # with textClosureList, which is used to put the strings in
(lib.textClosureList extensionTexts extNames)} # the right order - if a plugin which is dependent on
${extraConfig} # 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)));
phpWithExtensions = symlinkJoin { extNames = map getExtName enabledExtensions;
name = "php-with-extensions-${version}"; extraInit = writeText "php-extra-init-${version}.ini" ''
inherit (php) version; ${lib.concatStringsSep "\n"
nativeBuildInputs = [ makeWrapper ]; (lib.textClosureList extensionTexts extNames)}
passthru = php.passthru // { ${extraConfig}
buildEnv = mkBuildEnv allArgs allExtensionFunctions; '';
withExtensions = mkWithExtensions allArgs allExtensionFunctions;
phpIni = "${phpWithExtensions}/lib/php.ini"; phpWithExtensions = symlinkJoin {
unwrapped = php; name = "php-with-extensions-${version}";
# Select the right php tests for the php version inherit (php) version;
tests = nixosTests."php${lib.strings.replaceStrings [ "." ] [ "" ] (lib.versions.majorMinor php.version)}"; nativeBuildInputs = [ makeWrapper ];
inherit (php-packages) extensions buildPecl; passthru = php.passthru // {
packages = php-packages.tools; buildEnv = mkBuildEnv allArgs allExtensionFunctions;
meta = php.meta // { withExtensions = mkWithExtensions allArgs allExtensionFunctions;
outputsToInstall = [ "out" ]; phpIni = "${phpWithExtensions}/lib/php.ini";
}; unwrapped = php;
# Select the right php tests for the php version
tests = nixosTests."php${lib.strings.replaceStrings [ "." ] [ "" ] (lib.versions.majorMinor php.version)}";
inherit (php-packages) extensions buildPecl;
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
wrapProgram $out/bin/php --set PHP_INI_SCAN_DIR $out/lib
fi
if test -e $out/bin/php-fpm; then
wrapProgram $out/bin/php-fpm --set PHP_INI_SCAN_DIR $out/lib
fi
if test -e $out/bin/phpdbg; then
wrapProgram $out/bin/phpdbg --set PHP_INI_SCAN_DIR $out/lib
fi
'';
}; };
in paths = [ php ];
phpWithExtensions); postBuild = ''
ln -s ${extraInit} $out/lib/php.ini
mkWithExtensions = prevArgs: prevExtensionFunctions: extensions: if test -e $out/bin/php; then
mkBuildEnv prevArgs prevExtensionFunctions { inherit extensions; }; wrapProgram $out/bin/php --set PHP_INI_SCAN_DIR $out/lib
in fi
stdenv.mkDerivation {
pname = "php";
inherit version; if test -e $out/bin/php-fpm; then
wrapProgram $out/bin/php-fpm --set PHP_INI_SCAN_DIR $out/lib
fi
enableParallelBuilding = true; if test -e $out/bin/phpdbg; then
wrapProgram $out/bin/phpdbg --set PHP_INI_SCAN_DIR $out/lib
fi
'';
};
in
phpWithExtensions);
nativeBuildInputs = [ autoconf automake bison flex libtool pkg-config re2c ] mkWithExtensions = prevArgs: prevExtensionFunctions: extensions:
++ lib.optional stdenv.isDarwin xcbuild; mkBuildEnv prevArgs prevExtensionFunctions { inherit extensions; };
in
stdenv.mkDerivation {
pname = "php";
buildInputs = inherit version;
# PCRE extension
[ pcre2 ]
# Enable sapis enableParallelBuilding = true;
++ lib.optional pearSupport [ libxml2.dev ]
# Misc deps nativeBuildInputs = [ autoconf automake bison flex libtool pkg-config re2c ]
++ lib.optional apxs2Support apacheHttpd ++ lib.optional stdenv.isDarwin xcbuild;
++ lib.optional argon2Support libargon2
++ lib.optional systemdSupport systemd
++ lib.optional valgrindSupport valgrind
;
CXXFLAGS = lib.optionalString stdenv.cc.isClang "-std=c++11"; buildInputs =
# PCRE extension
[ pcre2 ]
configureFlags = # Enable sapis
# Disable all extensions ++ lib.optional pearSupport [ libxml2.dev ]
[ "--disable-all" ]
# PCRE # Misc deps
++ lib.optionals (lib.versionAtLeast version "7.4") [ "--with-external-pcre=${pcre2.dev}" ] ++ lib.optional apxs2Support apacheHttpd
++ lib.optionals (lib.versions.majorMinor version == "7.3") [ "--with-pcre-regex=${pcre2.dev}" ] ++ lib.optional argon2Support libargon2
++ lib.optionals (lib.versionOlder version "7.3") [ "--with-pcre-regex=${pcre2.dev}" ] ++ lib.optional systemdSupport systemd
++ [ "PCRE_LIBDIR=${pcre2}" ] ++ lib.optional valgrindSupport valgrind
;
CXXFLAGS = lib.optionalString stdenv.cc.isClang "-std=c++11";
configureFlags =
# Disable all extensions
[ "--disable-all" ]
# PCRE
++ lib.optionals (lib.versionAtLeast version "7.4") [ "--with-external-pcre=${pcre2.dev}" ]
++ lib.optionals (lib.versions.majorMinor version == "7.3") [ "--with-pcre-regex=${pcre2.dev}" ]
++ lib.optionals (lib.versionOlder version "7.3") [ "--with-pcre-regex=${pcre2.dev}" ]
++ [ "PCRE_LIBDIR=${pcre2}" ]
# Enable sapis # Enable sapis
++ lib.optional (!cgiSupport) "--disable-cgi" ++ lib.optional (!cgiSupport) "--disable-cgi"
++ lib.optional (!cliSupport) "--disable-cli" ++ lib.optional (!cliSupport) "--disable-cli"
++ lib.optional fpmSupport "--enable-fpm" ++ lib.optional fpmSupport "--enable-fpm"
++ lib.optional pearSupport [ "--with-pear" "--enable-xml" "--with-libxml" ] ++ lib.optional pearSupport [ "--with-pear" "--enable-xml" "--with-libxml" ]
++ lib.optionals (pearSupport && (lib.versionOlder version "7.4")) [ ++ lib.optionals (pearSupport && (lib.versionOlder version "7.4")) [
"--enable-libxml" "--enable-libxml"
"--with-libxml-dir=${libxml2.dev}" "--with-libxml-dir=${libxml2.dev}"
] ]
++ lib.optional pharSupport "--enable-phar" ++ lib.optional pharSupport "--enable-phar"
++ lib.optional (!phpdbgSupport) "--disable-phpdbg" ++ lib.optional (!phpdbgSupport) "--disable-phpdbg"
# Misc flags # Misc flags
++ lib.optional apxs2Support "--with-apxs2=${apacheHttpd.dev}/bin/apxs" ++ lib.optional apxs2Support "--with-apxs2=${apacheHttpd.dev}/bin/apxs"
++ lib.optional argon2Support "--with-password-argon2=${libargon2}" ++ lib.optional argon2Support "--with-password-argon2=${libargon2}"
++ lib.optional cgotoSupport "--enable-re2c-cgoto" ++ lib.optional cgotoSupport "--enable-re2c-cgoto"
++ lib.optional embedSupport "--enable-embed" ++ lib.optional embedSupport "--enable-embed"
++ lib.optional (!ipv6Support) "--disable-ipv6" ++ lib.optional (!ipv6Support) "--disable-ipv6"
++ lib.optional systemdSupport "--with-fpm-systemd" ++ lib.optional systemdSupport "--with-fpm-systemd"
++ lib.optional valgrindSupport "--with-valgrind=${valgrind.dev}" ++ lib.optional valgrindSupport "--with-valgrind=${valgrind.dev}"
++ lib.optional (ztsSupport && (lib.versionOlder version "8.0")) "--enable-maintainer-zts" ++ lib.optional (ztsSupport && (lib.versionOlder version "8.0")) "--enable-maintainer-zts"
++ lib.optional (ztsSupport && (lib.versionAtLeast version "8.0")) "--enable-zts" ++ lib.optional (ztsSupport && (lib.versionAtLeast version "8.0")) "--enable-zts"
# Sendmail # Sendmail
++ [ "PROG_SENDMAIL=${system-sendmail}/bin/sendmail" ] ++ [ "PROG_SENDMAIL=${system-sendmail}/bin/sendmail" ]
; ;
hardeningDisable = [ "bindnow" ]; hardeningDisable = [ "bindnow" ];
preConfigure = preConfigure =
# Don't record the configure flags since this causes unnecessary # Don't record the configure flags since this causes unnecessary
# runtime dependencies # runtime dependencies
'' ''
for i in main/build-defs.h.in scripts/php-config.in; do for i in main/build-defs.h.in scripts/php-config.in; do
substituteInPlace $i \ substituteInPlace $i \
--replace '@CONFIGURE_COMMAND@' '(omitted)' \ --replace '@CONFIGURE_COMMAND@' '(omitted)' \
--replace '@CONFIGURE_OPTIONS@' "" \ --replace '@CONFIGURE_OPTIONS@' "" \
--replace '@PHP_LDFLAGS@' "" --replace '@PHP_LDFLAGS@' ""
done done
export EXTENSION_DIR=$out/lib/php/extensions export EXTENSION_DIR=$out/lib/php/extensions
'' ''
# PKG_CONFIG need not be a relative path # PKG_CONFIG need not be a relative path
+ lib.optionalString (! lib.versionAtLeast version "7.4") '' + lib.optionalString (! lib.versionAtLeast version "7.4") ''
for i in $(find . -type f -name "*.m4"); do for i in $(find . -type f -name "*.m4"); do
substituteInPlace $i \ substituteInPlace $i \
--replace 'test -x "$PKG_CONFIG"' 'type -P "$PKG_CONFIG" >/dev/null' --replace 'test -x "$PKG_CONFIG"' 'type -P "$PKG_CONFIG" >/dev/null'
done done
'' + '' '' + ''
./buildconf --copy --force ./buildconf --copy --force
if test -f $src/genfiles; then if test -f $src/genfiles; then
./genfiles ./genfiles
fi fi
'' + lib.optionalString stdenv.isDarwin '' '' + lib.optionalString stdenv.isDarwin ''
substituteInPlace configure --replace "-lstdc++" "-lc++" substituteInPlace configure --replace "-lstdc++" "-lc++"
''; '';
postInstall = '' postInstall = ''
test -d $out/etc || mkdir $out/etc test -d $out/etc || mkdir $out/etc
cp php.ini-production $out/etc/php.ini cp php.ini-production $out/etc/php.ini
''; '';
postFixup = '' postFixup = ''
mkdir -p $dev/bin $dev/share/man/man1 mkdir -p $dev/bin $dev/share/man/man1
mv $out/bin/phpize $out/bin/php-config $dev/bin/ mv $out/bin/phpize $out/bin/php-config $dev/bin/
mv $out/share/man/man1/phpize.1.gz \ mv $out/share/man/man1/phpize.1.gz \
$out/share/man/man1/php-config.1.gz \ $out/share/man/man1/php-config.1.gz \
$dev/share/man/man1/ $dev/share/man/man1/
''; '';
src = fetchurl { src = fetchurl {
url = "https://www.php.net/distributions/php-${version}.tar.bz2"; url = "https://www.php.net/distributions/php-${version}.tar.bz2";
inherit sha256; inherit sha256;
}; };
patches = [ ./fix-paths-php7.patch ] ++ extraPatches; patches = [ ./fix-paths-php7.patch ] ++ extraPatches;
separateDebugInfo = true; separateDebugInfo = true;
outputs = [ "out" "dev" ]; outputs = [ "out" "dev" ];
passthru = { passthru = {
buildEnv = mkBuildEnv {} []; buildEnv = mkBuildEnv {} [];
withExtensions = mkWithExtensions {} []; withExtensions = mkWithExtensions {} [];
inherit ztsSupport; inherit ztsSupport;
}; };
meta = with lib; { meta = with lib; {
description = "An HTML-embedded scripting language"; description = "An HTML-embedded scripting language";
homepage = "https://www.php.net/"; homepage = "https://www.php.net/";
license = licenses.php301; license = licenses.php301;
maintainers = teams.php.members; maintainers = teams.php.members;
platforms = platforms.all; platforms = platforms.all;
outputsToInstall = [ "out" "dev" ]; outputsToInstall = [ "out" "dev" ];
}; };
}; };
in generic in generic