PHP Composer does not find installed php extensions

Hello, I have a Problem using the PHP composer on NixOS, so I have installed PHP with some extensions that I need for a project(Magento2) with nix shell:

let
  pkgs = import <nixpkgs> { };

  packages = with pkgs; [
     (pkgs.php.buildEnv {
        extensions = ({ enabled, all }: enabled ++ (with all; [
                xdebug
                bcmath
                dom
                imagick
                intl
                opcache
                pdo
                pdo_mysql
                soap
                zip
                xsl
                mbstring
                gd
        ]));
        extraConfig = ''
          xdebug.mode=debug
        '';
      })
      phpPackages.composer
  ];
in
pkgs.mkShell {
  buildInputs = packages;
}

And now I have the problem that PHP is installing fine every extension is registered and lists with php -m so that works I tested the extensions that they really work and they do. Now to the fun part I need composer to install the magento2 Project the problem is that the composer install script requires some PHP modules( xsl mysql etc…) and composer does not recognize the PHP.ini that PHP is using, so the composer fails to install

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2
Creating a "magento/project-community-edition" project at "./magento2"
Installing magento/project-community-edition (2.4.6-p1)
  - Installing magento/project-community-edition (2.4.6-p1): Extracting archive
Created project in /home/titus/WebstormProjects/Magento2DevSetup/magento2
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires magento/product-community-edition 2.4.6-p1 -> satisfiable by magento/product-community-edition[2.4.6-p1].
    - magento/product-community-edition 2.4.6-p1 requires ext-xsl * -> it is missing from your system. Install or enable PHP's xsl extension.

To enable extensions, verify that they are enabled in your .ini files:
    - /nix/store/ss4yv13gny44dj4svmlgq7lasikmjz62-php-with-extensions-8.1.20/lib/php.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-xsl` to temporarily ignore these required extensions.

The problem I suspect is causing this is that composer does not get its .ini from php --ini and just uses the registered php.ini but has its own ant the PHP plugins are not registered there how can I fix it why is this the case shouldn’t composer do this automatically?

Did you manage to solve the problem?

Problem can be, that you have more php instalation on your system and composer is run with other you expected.
Try look to composer executable file:

  • which composer
  • cat “that file”

In my case i have two instalation of php with two configuration. One in /etc/bin/php82 other in /etc/local/bin/php

It was the same versions, but each loaded diferent configs

Here is link to github with detailed explanation of potentional reason docker - Wrong PHP version used when installing composer with Alpine's apk command - Stack Overflow

To me it looks like the php used within Composer is not loading the xsl extension, but I may be wrong.

Edit: I just tested and the PHP used by composer doesn’t load the XSL extension by default, see:

❯ type composer
composer is /nix/store/sjl2yf904fa65psqrakjn4fx47f0cjq0-composer-2.6.6/bin/composer
❯ nix-store --query --tree /nix/store/sjl2yf904fa65psqrakjn4fx47f0cjq0-composer-2.6.6 | grep -i php-with
├───/nix/store/kkgizaxdxjbk9fjd9h31km35apl4l80a-php-with-extensions-8.2.14
│   └───/nix/store/kkgizaxdxjbk9fjd9h31km35apl4l80a-php-with-extensions-8.2.14 [...]
❯ /nix/store/kkgizaxdxjbk9fjd9h31km35apl4l80a-php-with-extensions-8.2.14/bin/php -m | grep -i xsl
❯ 

I can reproduce the issue:

❯ composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2
Creating a "magento/project-community-edition" project at "./magento2"
Warning from repo.magento.com: You haven't provided your Magento authentication keys. For instructions, visit https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html
    Authentication required (repo.magento.com):
      Username: 
      Password: 
Do you want to store credentials for repo.magento.com in /home/pol/.config/composer/auth.json ? [Yn] Y
Installing magento/project-community-edition (2.4.6-p3)
  - Downloading magento/project-community-edition (2.4.6-p3)
  - Installing magento/project-community-edition (2.4.6-p3): Extracting archive
Created project in /home/pol/Code/loophp/collection/magento2
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires magento/product-community-edition 2.4.6-p3 -> satisfiable by magento/product-community-edition[2.4.6-p3].
    - magento/product-community-edition 2.4.6-p3 requires ext-xsl * -> it is missing from your system. Install or enable PHP's xsl extension.

To enable extensions, verify that they are enabled in your .ini files:
    - /nix/store/kkgizaxdxjbk9fjd9h31km35apl4l80a-php-with-extensions-8.2.14/lib/php.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-xsl` to temporarily ignore these required extensions.
✘     

A fix is incoming very soon.

Here’s a temporary solution until I discuss with the PHP team what to do with this, if we fix it in nixpkgs.

let
  pkgs = import <nixpkgs> { };

  packages =
    let
      phpForRuntimeWithXDebug = (pkgs.php.buildEnv {
        extensions = ({ enabled, all }: enabled ++ (with all; [
          xdebug
          bcmath
          dom
          imagick
          intl
          opcache
          pdo
          pdo_mysql
          soap
          zip
          xsl
          mbstring
          gd
        ]));
        extraConfig = ''
          xdebug.mode=debug
        '';
      });
    in
    [
      phpForRuntimeWithXDebug
      (pkgs.php.withExtensions ({ enabled, all }: enabled ++ [ all.xsl ])).packages.composer
    ];
in
pkgs.mkShell {
  inherit packages;
}