Issue with registering the `phpExtensions.redis`

Hello NixOS Community,

I hope you’re all doing well. I’m currently facing an issue with registering the php74Extensions.redis in my NixOS environment, and I’m seeking some guidance to resolve it.
I’m able to get xdebug to correctly register with the zend_extension = "${php.php74Extensions.xdebug}/lib/php/extensions/" and I’ve can see the exists in the nixstore path /nix/store/hnjkll3gvx7nm8i7vm1mc1cpa4b1p3lh-php-redis-5.3.4/lib/php/extensions/ for the php74Extensions.redis package. However phpinfo fails to register the redis package (xdebug is showing as expected and changed to the config or removing the entry reflect the phpinfo.)

Here’s a brief overview of my configuration:


{ config, pkgs, lib, ... }:
  php = import
    (builtins.fetchTarball {
      url = ""; #7.4.29 php
    { };
  imports =
      # Include the results of the hardware scan.
      (import /home/stotes/nix/server/nginx-php.nix { inherit config php lib pkgs; })
    # ... continues


{ config, pkgs, lib, php, ... }:
  environment.systemPackages = with php; [

  services.phpfpm.phpOptions = ''
    date.timezone = Australia/Brisbane
    extension = "${php.php74Extensions.redis}/lib/php/extensions/"
    zend_extension = "${php.php74Extensions.xdebug}/lib/php/extensions/"

nix-created php.ini entries:

date.timezone = Australia/Brisbane
extension = "/nix/store/hnjkll3gvx7nm8i7vm1mc1cpa4b1p3lh-php-redis-5.3.4/lib/php/extensions/"
zend_extension = "/nix/store/hsprflbbk5a0hqaysm7vaspqmn2l1nyg-php-xdebug-3.0.4/lib/php/extensions/"

Despite my configuration, the php74Extensions.redis package is not registering as expected. I’ve followed the NixOS documentation and community forums but couldn’t find a solution. Can someone please guide me on what might be causing this issue or any steps I can take to troubleshoot it further?

Any help or insights would be greatly appreciated. Thank you in advance for your assistance!

Plopping random packages into environment.systemPackages will rarely work if you need anything more complex than having the package’s programs on PATH or registering its systemd services. This is doubly true for libraries. And if you are using a NixOS module, you will need to pass the package to it explicitly using a separate option if you want to override, in this case services.phpfpm.phpPackage.

So your main issue is that php-fpm NixOS module continues to use the default PHP, not the one you added in environment.systemPackages.

Second, while enabling extensions in config manually might work if you get everything right, it is much easier to create a PHP derivation with extensions enabled using php.withExtensions function, as described in the manual.

And it is not clear if you are actually using php-pfm NixOS module or just running php on command line. services.phpfpm.phpOptions only applies to php-fpm NixOS module, which requires a bit more configuration.

Also note that by using an older version of Nixpkgs, you are getting a snapshot of one point in time, where much of the software versions now have widely known serious security vulnerabilities. Just the PHP 7.4.29 you would be using (last version before PHP 7.4 has been removed from Nixpkgs, released on 2022-04-14) received 29 versions with bugfixes, including critical CVE fixes and PHP depends on other projects like curl as well.

I recommend using GitHub - fossar/nix-phps: Repository of Nix expressions for old PHP versions, which not only contains latest PHP 7.4 version but also regularly updates Nixpkgs version it is based on so dependencies are not stuck in insecure state for eternity. Though note that PHP 7.4 itself has only four days of upstream security support left so I would hurry to migrate away from it anyway.

Disclaimer: I started the nix-phps project.

1 Like