Add some extra extensions to php in systemPackages

I have php working with extra extensions in a phpfpm pool. The entire config is posted below, for people who are searching for how to setup nextcloud in their flake.

My question is: how do I install PHP in the same way, globally? So, in environment.systemPackages. The following does not work:

  environment.systemPackages = with pkgs; [
    pkgs.nodejs
    pkgs.nodePackages.node-pre-gyp
    pkgs.php83.buildEnv {
      extensions = {enabled, all}: enabled ++ (with all; [
        apcu
        bcmath
        gmp
        imagick
        opcache
        pdo
        pdo_pgsql
        redis
      ]);
    }
  ];

Hope someone can tell me how to do this.

Here is where it does work in this way:

services.phpfpm.pools.cloud = {
  user="foo";
  group = "foo";
    phpPackage = pkgs.php83.buildEnv {
      extensions = {enabled, all}: enabled ++ (with all; [
        apcu
        bcmath
        gmp
        imagick
        opcache
        pdo
        pdo_pgsql
        redis
      ]);
      extraConfig = ''
        output_buffering = off
        memory_limit = 1G
        apc.enable_cli = 1
        opcache.memory_consumption=256
        opcache.interned_strings_buffer=64
        opcache.max_accelerated_files=32531
        opcache.validate_timestamps=0
        opcache.enable_cli=1
      '';
    };
    phpEnv = {
      PATH = lib.strings.makeBinPath [
        pkgs.coreutils
        pkgs.imagemagick
        pkgs.ffmpeg
        pkgs.exiftool
        pkgs.nodejs
        pkgs.nodePackages.node-pre-gyp
      ];
    };
    settings = {
      pm = "dynamic";
      "listen.owner" = config.services.nginx.user;
      "pm.max_children" = 5;
      "pm.start_servers" = 2;
      "pm.min_spare_servers" = 1;
      "pm.max_spare_servers" = 3;
      "pm.max_requests" = 500;

    };

Answering my own question because like way too often the solution is found right after posting the question. :man_facepalming: Apparently I needed to add a parentheses etc.

  environment.systemPackages = [
    pkgs.nodejs
    pkgs.nodePackages.node-pre-gyp
    (pkgs.php83.buildEnv {
      extensions = ({enabled, all}: enabled ++ (with all; [
        apcu
        bcmath
        gmp
        imagick
        opcache
        pdo
        pdo_pgsql
        redis
      ]));
      extraConfig = ''
        apc.enable_cli = 1
      '';
    })
  ];