Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php.packages: Make packages overridable #107044

Merged
merged 2 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions doc/languages-frameworks/php.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,21 @@ Example of building `composer` with additional extensions:
enabled ++ (with all; [ imagick redis ]))
).packages.composer
```

### Overriding PHP packages {#ssec-php-user-guide-overriding-packages}

`php-packages.nix` form a scope, allowing us to override the packages defined within. For example, to apply a patch to a `mysqlnd` extension, you can simply pass an overlay-style function to `php`’s `packageOverrides` argument:

```nix
php.override {
packageOverrides = final: prev: {
extensions = prev.extensions // {
mysqlnd = prev.extensions.mysqlnd.overrideAttrs (attrs: {
patches = attrs.patches or [] ++ [
];
});
};
};
}
```
8 changes: 5 additions & 3 deletions pkgs/development/interpreters/php/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let
, version
, sha256
, extraPatches ? []
, packageOverrides ? (final: prev: {})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python nowadays also supports overrideScope' but it has not been documented yet. My intention is to deprecate this packageOverrides because it does not compose.

Copy link
Member Author

@jtojnar jtojnar Dec 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does actually compose:

let
  pkgs = import ./. { };

  idOverlay = final: prev: {};
  composeOverlays =
    old:
    new:

    final:
    prev:

    let
      oldInstantiated = old final prev;
      prevWithOld = prev // oldInstantiated;
    in
      oldInstantiated // new final prevWithOld;

  oldPhp = pkgs.php.override {
    packageOverrides = final: prev: {
      extensions = prev.extensions // {
        mysqlnd = prev.extensions.mysqlnd.overrideAttrs (attrs: {
          foo = "foo";
        });
      };
    };
  };
in
  oldPhp.override (oldOverrides: {
    packageOverrides = composeOverlays (oldOverrides.packageOverrides or idOverlay) (final: prev: {
      extensions = prev.extensions // {
        mysqlnd = prev.extensions.mysqlnd.overrideAttrs (attrs: {
          foo = prev.extensions.mysqlnd.foo or "" + "bar";
        });
      };
    });
  })

But yeah, it is a mouthful.


# Sapi flags
, cgiSupport ? true
Expand Down Expand Up @@ -49,8 +50,8 @@ let
php = generic filteredArgs;

php-packages = (callPackage ../../../top-level/php-packages.nix {
php = phpWithExtensions;
});
phpPackage = phpWithExtensions;
}).overrideScope' packageOverrides;

allExtensionFunctions = prevExtensionFunctions ++ [ extensions ];
enabledExtensions =
Expand Down Expand Up @@ -112,7 +113,8 @@ let
phpIni = "${phpWithExtensions}/lib/php.ini";
unwrapped = php;
tests = nixosTests.php;
inherit (php-packages) packages extensions buildPecl;
inherit (php-packages) extensions buildPecl;
packages = php-packages.tools;
meta = php.meta // {
outputsToInstall = [ "out" ];
};
Expand Down
15 changes: 5 additions & 10 deletions pkgs/top-level/php-packages.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{ stdenv, lib, pkgs, fetchgit, php, autoconf, pkgconfig, re2c
{ stdenv, lib, pkgs, fetchgit, phpPackage, autoconf, pkgconfig, re2c
, gettext, bzip2, curl, libxml2, openssl, gmp, icu64, oniguruma, libsodium
, html-tidy, libzip, zlib, pcre, pcre2, libxslt, aspell, openldap, cyrus_sasl
, uwimap, pam, libiconv, enchant1, libXpm, gd, libwebp, libjpeg, libpng
, freetype, libffi, freetds, postgresql, sqlite, net-snmp, unixODBC, libedit
, readline, rsync, fetchpatch, valgrind
}:

let
lib.makeScope pkgs.newScope (self: with self; {
buildPecl = import ../build-support/build-pecl.nix {
php = php.unwrapped;
inherit lib;
Expand All @@ -21,15 +21,10 @@ let

pcre' = if (lib.versionAtLeast php.version "7.3") then pcre2 else pcre;

callPackage = pkgs.newScope {
inherit mkDerivation php buildPecl pcre';
};
in
{
inherit buildPecl;
php = phpPackage;

# This is a set of interactive tools based on PHP.
packages = {
tools = {
box = callPackage ../development/php-packages/box { };

composer = callPackage ../development/php-packages/composer { };
Expand Down Expand Up @@ -550,4 +545,4 @@ in

# Produce the final attribute set of all extensions defined.
in builtins.listToAttrs namedExtensions);
}
})