3
submitted 1 year ago* (last edited 1 year ago) by rikudou@lemmings.world to c/nixos@infosec.pub

Hi there! I'm trying to make php and composer work. I have this in environment.systemPackages:

    (pkgs.php82.buildEnv {
      extensions = ({ enabled, all }: enabled ++ (with all; [
        xdebug
        redis
      ]));
      extraConfig = ''
        memory_limit=2G
        xdebug.mode=debug
      '';
    })
    php82Extensions.redis

The problem is that while running php -m correctly prints that redis extension is installed, composer does not, because it uses a different php:

  • file $(which php) prints the path /nix/store/igx8j4qjxy9jyj8kjyccwarnzqq5vsml-php-with-extensions-8.2.9/bin/php
  • cat $(which composer) shows that it's a wrapper for '/nix/store/lv4prxa52zifr54ws56iz3b9kdhs1b5w-php-with-extensions-8.2.9/bin/php' --add-flags '/nix/store/avqj0662f4gg2s875zlbbjajx6fm6bl0-php-composer-2.5.5/libexec/composer/composer.phar'

Note that the path to php is different. Is there any way to correct it on my side? I'd like to avoid having to install composer manually

top 5 comments
sorted by: hot top controversial new old
[-] aanderse@infosec.pub 1 points 1 year ago

This is what you want in your configuration.nix:

{ config, pkgs, lib, ... }:
let
   custom-php = pkgs.php82.buildEnv {
      extensions = ({ enabled, all }: enabled ++ (with all; [
        xdebug
        redis
      ]));
      extraConfig = ''
        memory_limit=2G
        xdebug.mode=debug
      '';
    };
in
{
  environment.systemPackages = [
    custom-php
    custom-php.packages.composer
  ];
}

Let me know how that works out for you.

[-] rikudou@lemmings.world 1 points 1 year ago

That worked! Thank you! How did you know how to solve it?

[-] aanderse@infosec.pub 2 points 1 year ago

I'm in the NixOS php maintainers team.

[-] rikudou@lemmings.world 1 points 1 year ago

And how could I find out something like this?

[-] aanderse@infosec.pub 1 points 1 year ago

Looks like you almost had it figured out. composer belongs to the phpPackages set, an alias for php.packages, and any package under that set should use the php package you specify. This way you can customize the php configuration for various programs.

And how could I find out something like this?

I briefly looked at the documentation and I'm not sure that this is specifically mentioned. Unless I missed it this would be nice to add to our documentation.

this post was submitted on 01 Sep 2023
3 points (71.4% liked)

NixOS

753 readers
1 users here now

NixOS is a Linux distribution built on top of the Nix package manager. Its declarative configuration allows reliable system upgrades via several official channels of stability and size.

This community discusses NixOS, Nix, and everything related.

founded 1 year ago
MODERATORS