From 2a9ed196febc3b8901bf2e319f104d9c3c372e12 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Tue, 26 Apr 2022 21:08:29 +0200 Subject: [PATCH 1/2] php-master: init at php-8.4.0.snapshot.c803402-20230907122631 Co-Authored-By: Pol Dellaiera --- .github/workflows/build.yaml | 16 ++++-- README.md | 1 + checks.nix | 2 +- flake.lock | 17 ++++++ flake.nix | 13 +++-- pkgs/php/master.nix | 100 +++++++++++++++++++++++++++++++++++ pkgs/phps.nix | 71 +++++++++++++++---------- 7 files changed, 186 insertions(+), 34 deletions(-) create mode 100644 pkgs/php/master.nix diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 025b4417..45f5cbb7 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -16,6 +16,7 @@ jobs: strategy: matrix: php: + - branch: 'master' - branch: '8.3' - branch: '8.2' - branch: '8.1' @@ -49,9 +50,18 @@ jobs: id: params run: | branch=${{ matrix.php.branch }} - major=${branch%%.*} - minor=${branch#*.} - attr=php$major$minor + if [[ "$branch" = "master" ]]; then + attr=php-master + version=$(nix-instantiate --eval --json -A "outputs.packages.x86_64-linux.${attr}.version") + # Strip quotes + version=${version//\"/} + major=${branch%%.*} + else + major=${branch%%.*} + minor=${branch#*.} + attr=php$major$minor + fi + echo "minor=$minor" >> $GITHUB_OUTPUT echo "major=$major" >> $GITHUB_OUTPUT echo "attr=$attr" >> $GITHUB_OUTPUT diff --git a/README.md b/README.md index 6fed4bd4..6baeea74 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ The following versions are currently available: - `php81` - `php82` - `php83` +- `php-master` (updated weekly) There is also a `php` package which is the alias of the default PHP version in Nixpkgs. diff --git a/checks.nix b/checks.nix index b322f85d..9325a053 100644 --- a/checks.nix +++ b/checks.nix @@ -5,7 +5,7 @@ }: let - phpPackages = builtins.filter (name: builtins.match "php[0-9]+" name != null) (builtins.attrNames packages); + phpPackages = builtins.filter (name: builtins.match "php([0-9]+|-master)" name != null) (builtins.attrNames packages); checks = { php = { diff --git a/flake.lock b/flake.lock index 57137ee6..80386ab0 100644 --- a/flake.lock +++ b/flake.lock @@ -32,10 +32,27 @@ "type": "github" } }, + "php-src": { + "flake": false, + "locked": { + "lastModified": 1694089591, + "narHash": "sha256-CWMlTDoqCmi8I8QTFvRobPkd9P+RAESieQb8ltr4VvM=", + "owner": "php", + "repo": "php-src", + "rev": "c8034021625cdd5392b2cb125b657ab5c3a95e42", + "type": "github" + }, + "original": { + "owner": "php", + "repo": "php-src", + "type": "github" + } + }, "root": { "inputs": { "flake-compat": "flake-compat", "nixpkgs": "nixpkgs", + "php-src": "php-src", "utils": "utils" } }, diff --git a/flake.nix b/flake.nix index c55dac3f..65cd41f8 100644 --- a/flake.nix +++ b/flake.nix @@ -10,10 +10,15 @@ nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + php-src = { + url = "github:php/php-src"; + flake = false; + }; + utils.url = "github:numtide/flake-utils"; }; - outputs = { self, flake-compat, nixpkgs, utils }: + outputs = { self, flake-compat, nixpkgs, php-src, utils }: # For each supported platform, utils.lib.eachDefaultSystem (system: let @@ -29,7 +34,7 @@ }; in rec { packages = { - inherit (pkgs) php php56 php70 php71 php72 php73 php74 php80 php81 php82 php83; + inherit (pkgs) php php56 php70 php71 php72 php73 php74 php80 php81 php82 php83 php-master; }; checks = import ./checks.nix { @@ -37,6 +42,8 @@ }; } ) // { - overlays.default = import ./pkgs/phps.nix nixpkgs.outPath; + overlays.default = import ./pkgs/phps.nix { + inherit nixpkgs php-src; + }; }; } diff --git a/pkgs/php/master.nix b/pkgs/php/master.nix new file mode 100644 index 00000000..5d0a4887 --- /dev/null +++ b/pkgs/php/master.nix @@ -0,0 +1,100 @@ +{ prev +, generic +, _mkArgs +, php-src +}: + +let + pear = prev.fetchurl { + url = "https://pear.php.net/install-pear-nozlib.phar"; + hash = "sha256-UblKVcsm030tNSA6mdeab+h7ZhANNz7MkFf4Z1iigjs="; + }; + + base-master = prev.callPackage generic (_mkArgs { + hash = null; + + version = + let + configureFile = "${php-src}/configure.ac"; + + extractVersionFromConfigureAc = configureText: + let + match = builtins.match ".*AC_INIT\\(\\[PHP],\\[([^]-]+)(-dev)?].*" configureText; + in + if match != null then builtins.head match else null; + + extractVersionFromConfigureAcPre74 = configureText: + let + match = builtins.match ".*PHP_MAJOR_VERSION=([0-9]+)\nPHP_MINOR_VERSION=([0-9]+)\nPHP_RELEASE_VERSION=([0-9]+)\n.*" configureText; + in + if match != null then prev.lib.concatMapStringsSep "." builtins.toString match else null; + + version = + let + configureText = builtins.readFile configureFile; + version = extractVersionFromConfigureAc configureText; + versionPre74 = extractVersionFromConfigureAcPre74 configureText; + + versionCandidates = prev.lib.optionals (builtins.pathExists configureFile) [ + version + versionPre74 + ]; + in + prev.lib.findFirst (version: version != null) "0.0.0+unknown" versionCandidates; + in + "${version}.snapshot.${php-src.shortRev}-${php-src.lastModifiedDate}"; + + phpAttrsOverrides = attrs: { + src = php-src; + + preInstall = attrs.preInstall or "" + '' + cp -f ${pear} ./pear/install-pear-nozlib.phar + ''; + }; + }); +in +base-master.withExtensions ({ all, ... }: with all; [ + bcmath + calendar + curl + ctype + dom + exif + fileinfo + filter + ftp + gd + gettext + gmp + iconv + intl + ldap + mbstring + mysqli + mysqlnd + opcache + openssl + pcntl + pdo + pdo_mysql + pdo_odbc + pdo_pgsql + pdo_sqlite + pgsql + posix + readline + session + simplexml + sockets + soap + sodium + sqlite3 + tokenizer + xmlreader + xmlwriter + zip + zlib +] +++ prev.lib.optionals (!prev.stdenv.isDarwin) [ + imap +]) diff --git a/pkgs/phps.nix b/pkgs/phps.nix index 00e7b2b6..e8f303ed 100644 --- a/pkgs/phps.nix +++ b/pkgs/phps.nix @@ -1,4 +1,7 @@ -nixpkgs: +{ + nixpkgs, + php-src, +}: # These are older versions of PHP removed from Nixpkgs. @@ -8,10 +11,14 @@ prev: let packageOverrides = import ./package-overrides.nix prev; + /* Composes package overrides (i.e. overlays that only take prev). */ + composeOverrides = a: b: prev.lib.composeExtensions (_: a) (_: b) { }; + _mkArgs = args: - { + args + // { inherit packageOverrides; # For passing pcre2 to generic.nix. @@ -20,8 +27,14 @@ let then prev.pcre2 else prev.pcre; + # Overrides attributes passed to the stdenv.mkDerivation for the unwrapped PHP + # in . + # This will essentially end up creating a derivation equivalent to the following: + # stdenv.mkDerivation (versionSpecificOverrides (commonOverrides { /* stuff passed to mkDerivation in generic.nix */ })) phpAttrsOverrides = - attrs: + let + commonOverrides = + attrs: { patches = @@ -46,14 +59,13 @@ let }) ]; - configureFlags = - attrs.configureFlags - ++ prev.lib.optionals (prev.lib.versionOlder args.version "7.4") [ - # phar extension’s build system expects hash or it will degrade. - "--enable-hash" - - "--enable-libxml" - "--with-libxml-dir=${prev.libxml2.dev}" + configureFlags = + attrs.configureFlags + ++ prev.lib.optionals (prev.lib.versionOlder args.version "7.4") [ + # phar extension’s build system expects hash or it will degrade. + "--enable-hash" + "--enable-libxml" + "--with-libxml-dir=${prev.libxml2.dev}" ] ++ prev.lib.optionals (prev.lib.versions.majorMinor args.version == "7.3") [ # Force use of pkg-config. @@ -72,20 +84,24 @@ let prev.libxcrypt ]; - preConfigure = - prev.lib.optionalString (prev.lib.versionOlder args.version "7.4") '' - # Workaround “configure: error: Your system does not support systemd.” - # caused by PHP build system expecting PKG_CONFIG variable to contain - # an absolute path on PHP ≤ 7.4. - # Also patches acinclude.m4, which ends up being used by extensions. - # https://github.com/NixOS/nixpkgs/pull/90249 - for i in $(find . -type f -name "*.m4"); do - substituteInPlace $i \ - --replace 'test -x "$PKG_CONFIG"' 'type -P "$PKG_CONFIG" >/dev/null' - done - '' - + attrs.preConfigure; - }; + preConfigure = + prev.lib.optionalString (prev.lib.versionOlder args.version "7.4") '' + # Workaround “configure: error: Your system does not support systemd.” + # caused by PHP build system expecting PKG_CONFIG variable to contain + # an absolute path on PHP ≤ 7.4. + # Also patches acinclude.m4, which ends up being used by extensions. + # https://github.com/NixOS/nixpkgs/pull/90249 + for i in $(find . -type f -name "*.m4"); do + substituteInPlace $i \ + --replace 'test -x "$PKG_CONFIG"' 'type -P "$PKG_CONFIG" >/dev/null' + done + '' + + attrs.preConfigure; + }; + + versionSpecificOverrides = args.phpAttrsOverrides or (attrs: { }); + in + composeOverrides commonOverrides versionSpecificOverrides; # For passing pcre2 to php-packages.nix. callPackage = @@ -117,8 +133,7 @@ let ); } ); - } - // args; + }; generic = "${nixpkgs}/pkgs/development/interpreters/php/generic.nix"; mkPhp = args: prev.callPackage generic (_mkArgs args); @@ -149,4 +164,6 @@ in php83 = prev.php83.override { inherit packageOverrides; }; + + php-master = import ./php/master.nix { inherit prev generic _mkArgs php-src; }; } From 5ef5053c024b728740caa9ca932b3cf1bb4ef047 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Fri, 8 Sep 2023 06:55:12 +0200 Subject: [PATCH 2/2] extensions: add `xdebug` extensions for PHP >= 8.3 --- pkgs/package-overrides.nix | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkgs/package-overrides.nix b/pkgs/package-overrides.nix index 9dc0c99c..e271afb3 100644 --- a/pkgs/package-overrides.nix +++ b/pkgs/package-overrides.nix @@ -729,7 +729,16 @@ in xdebug = # xdebug versions were determined using https://xdebug.org/docs/compat - if lib.versionAtLeast prev.php.version "8.0" then + if lib.versionAtLeast prev.php.version "8.3" then + prev.extensions.xdebug.overrideAttrs (attrs: { + name = "xdebug-3.3.0alpha2"; + version = "3.3.0alpha2"; + src = pkgs.fetchurl { + url = "http://pecl.php.net/get/xdebug-3.3.0alpha2.tgz"; + hash = "sha256-wcV71/taOpqs2ckX4vZT1TOWpl1JiP2s6EgPyX9EI6c="; + }; + }) + else if lib.versionAtLeast prev.php.version "8.0" then prev.extensions.xdebug else if lib.versionAtLeast prev.php.version "7.2" then prev.extensions.xdebug.overrideAttrs (attrs: {