diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 90f89842..c52c4ad6 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -14,6 +14,7 @@ jobs: strategy: matrix: php: + - branch: 'master' - branch: '8.1' - branch: '8.0' - branch: '7.4' @@ -40,9 +41,17 @@ 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 "::set-output name=major::$major" echo "::set-output name=attr::$attr" diff --git a/README.md b/README.md index a1884df4..8a41b04a 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ We use [Cachix](https://app.cachix.org/cache/fossar) to store `x86_64-linux` bin This package is regularly updated to match latest Nixpkgs and the PHP packages use the [same API as those in Nixpkgs](https://nixos.org/manual/nixpkgs/unstable/#sec-php). -The following versions are currently supported: +The following versions are currently available: - `php56` - `php70` @@ -24,6 +24,7 @@ The following versions are currently supported: - `php74` - `php80` - `php81` +- `php-master` 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 6e90a69e..d590579c 100644 --- a/flake.lock +++ b/flake.lock @@ -32,10 +32,27 @@ "type": "github" } }, + "php-src": { + "flake": false, + "locked": { + "lastModified": 1650992281, + "narHash": "sha256-vYjYNfpQUBw3FO3G7mOjThpcX75COqdscD/4j7/C1lI=", + "owner": "php", + "repo": "php-src", + "rev": "36486106d99fedca4c8938f8629742835269f477", + "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/pkgs/package-overrides.nix b/pkgs/package-overrides.nix index 58e3d718..e916e0ef 100644 --- a/pkgs/package-overrides.nix +++ b/pkgs/package-overrides.nix @@ -9,6 +9,8 @@ prev: let patchName = patch: patch.name or (builtins.baseNameOf patch); inherit (pkgs) lib; + + isBuiltFromGit = lib.hasInfix "+date=" prev.php.version; in { @@ -30,6 +32,29 @@ in composer = final.callPackage ./composer/2.2.nix { }; }; + # TODO: Address this in Nixpkgs. + mkExtension = + if lib.hasInfix "+date=" prev.php.version + then + attrs: + + (prev.mkExtension attrs).overrideAttrs (attrs: { + # PHP obtained from Git contains files directly in the top-level directory, + # which will be placed in Nix store. The generic builder will then copy it + # to the /build sandbox as its basename with hash stripped (e.g. source/). + # `mkExtension` expects that PHP source will be extracted into `php-«version»/` + # directory like the tarball does and sets sourceRoot accordingly. + # Let’s unset the `sourceRoot`, leaving it to `unpackPhase` to find the source + # directory, and only change to the extension directory afterwards. + sourceRoot = null; + prePatch = '' + cd "${lib.removePrefix "php-${prev.php.version}/" attrs.sourceRoot}" + '' + attrs.prePatch; + }) + else + prev.mkExtension; + + extensions = prev.extensions // { apcu = if lib.versionOlder prev.php.version "7.0" then @@ -319,6 +344,15 @@ in ourPatches ++ upstreamPatches; }); + tokenizer = + prev.extensions.tokenizer.overrideAttrs (attrs: { + nativeBuildInputs = attrs.nativeBuildInputs or [ ] ++ lib.optionals isBuiltFromGit [ + # Tarballs ship pre-generated parser files. + pkgs.bison + pkgs.flex + ]; + }); + xdebug = # xdebug versions were determined using https://xdebug.org/docs/compat if lib.versionAtLeast prev.php.version "7.2" then diff --git a/pkgs/phps.nix b/pkgs/phps.nix index 6a399f5b..36a65c4d 100644 --- a/pkgs/phps.nix +++ b/pkgs/phps.nix @@ -11,10 +11,13 @@ 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. @@ -23,34 +26,44 @@ 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: - - { - patches = - let - upstreamPatches = - attrs.patches or [ ]; - - ourPatches = - prev.lib.optionals (prev.lib.versions.majorMinor args.version == "7.2") [ - # Building the bundled intl extension fails on Mac OS. - # See https://bugs.php.net/bug.php?id=76826 for more information. - (prev.pkgs.fetchpatch { - url = "https://bugs.php.net/patch-display.php?bug_id=76826&patch=bug76826.poc.0.patch&revision=1538723399&download=1"; - sha256 = "aW+MW9Kb8N/yBO7MdqZMZzgMSF7b+IMLulJKgKPWrUA="; - }) + let + commonOverrides = + attrs: + + { + patches = + let + upstreamPatches = + attrs.patches or [ ]; + + ourPatches = + prev.lib.optionals (prev.lib.versions.majorMinor args.version == "7.2") [ + # Building the bundled intl extension fails on Mac OS. + # See https://bugs.php.net/bug.php?id=76826 for more information. + (prev.pkgs.fetchpatch { + url = "https://bugs.php.net/patch-display.php?bug_id=76826&patch=bug76826.poc.0.patch&revision=1538723399&download=1"; + sha256 = "aW+MW9Kb8N/yBO7MdqZMZzgMSF7b+IMLulJKgKPWrUA="; + }) + ]; + in + ourPatches ++ upstreamPatches; + + 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" ]; - in - ourPatches ++ upstreamPatches; + }; - 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" - ]; - }; + versionSpecificOverrides = args.phpAttrsOverrides or (attrs: { }); + in + composeOverrides commonOverrides versionSpecificOverrides; # For passing pcre2 to php-packages.nix. callPackage = @@ -72,7 +85,7 @@ let else prev.pcre; }); }); - } // args; + }; generic = "${nixpkgs}/pkgs/development/interpreters/php/generic.nix"; @@ -115,6 +128,57 @@ let }) ]; }); + + base-master = + prev.callPackage generic (_mkArgs { + 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}.pre+date=${php-src.lastModifiedDate}"; + sha256 = null; + + phpAttrsOverrides = attrs: { + src = php-src; + configureFlags = attrs.configureFlags ++ [ + # install-pear-nozlib.phar (normally shipped in tarball) would need to be downloaded. + "--without-pear" + ]; + }; + }); in { php56 = @@ -393,4 +457,56 @@ in prev.php81.override { inherit packageOverrides; }; + + php-master = + 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 + ]) + ); }