-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
nixos/php: init new php module for command line usage #55460
Conversation
I'm maybe a outsider on this opinion, but I'd be more in favor of someone just using environment.etc."php.ini".text to set their PHP config options than make a wrapper and module. |
@grahamc my concern with that approach was that maybe httpd and phpfpm would read that configuration as well which would obviously have problems if you're mixing and matching php versions between httpd, phpfpm, and command line php. I'll check if this if the case or not and report back. |
@grahamc yeah so I tested mod_php and it didn't pickup any php configuration from /etc. So I guess I'm indifferent to this PR. Thanks |
@grahamc spoke too soon... mod_php actually did read in config from /etc so I'm back to thinking this PR is a good idea because the environment.etc way "pollutes" at least mod_php, if not php-fpm as well. As of 19.03 I believe php-fpm even explicitly supports running multiple versions of php concurrently so especially if php-fpm is picking up files in /etc this would be bad. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I welcome this module, I mostly use php on command line and I think this would be great :-)
Just out of interest: wouldn't it make more sense to solve this on a package-level? So basically something like this: php.override {
config = writeText "php.ini" ''
; php cfg
'';
} At least this is (more or less) what I'm currently doing for me PHP installation: https://gitlab.com/Ma27/nixexprs/blob/master/pkgs/php/overlay.nix |
@Ma27 Recompiling php and all the extensions you use because you want to make a minor adjustment to your php.ini file doesn't sound fun. Now you've got me interested... what benefit are you getting from recompiling php every time you need to change a runtime option? |
I don't recompile PHP all the time, all changes are happening in a You could implement this as well in But don't get me wrong, this is mainly a suggestion how I'd like to prefer this (as someone using PHP quite regularly in his job currently), it's still possible that other maitainers disagree with me :) |
Ah I see! That makes sense. Thanks for explaining. |
To summarize so far there are 3 proposed solutions for providing a php.ini file to command line php:
This has the issue that it is applied to all instances of php on the system, regardless of version. phpfpm can run multiple versions of php at the same time so you wouldn't be able to put anything version specific in this. Basically introduces side effects and moves away from reproducibility in some cases.
This is a nice solution. It has added benefit that it can be used on anything (mod_php, phpfpm, cli). The downside is that it is inconsistent with how every other instance of php works in NixOS, as in both mod_php and phpfpm already have phpOptions.
I still like my approach the best as it is consistent with the existing NixOS infrastructure. Simply so this PR doesn't stagnate I'd love to get some direction on which way to go with this. |
Wouldn't number 2 cause a rebuild of PHP each time since the inputs are changed? Personally I like the overlay that @Ma27 linked that just wraps PHP with a custom file pointed out since that won't cause any rebuilds. But at the same time it would be nice to have something more discoverable than creating a wrapper package by your own, which works for the more experienced nix user, which number 3 provides. But that one also have issues mentioned, like if you want to use more than one version of PHP. But then number 1 have even bigger issues, like if you define modules that are incompatible with older versions of PHP and then you launch an older version of PHP in a nix-shell which may break or so. I think I'm mostly happy with some kind of wrapper package (like number 2) where you can provide the php derivation and additional configuration wrapped in. Then that derivation can be discoverable in searches and just 2 parameters to override to switch version of PHP and change the ini-file. And it won't cause rebuilds of PHP. |
Not necessarily. If such an option is set, the expression can return a |
@Ma27 are you interested in putting together a PR for your |
Yeah, why not actually :) |
Thank you! |
@Ma27 ping. Any chance for |
Initially discussed in NixOS#55460. This patch adds a `buildEnv` function to `php` that has the following features: * `php.buildEnv { extraConfig = /* ... */; }` to specify custom `php.ini` args for the CLI. * `php.buildEnv { exts = phpPackages: [phpPackages.apcu] }` to create a PHP interpreter for the CLI with the `apcu` extension.
Initially discussed in NixOS#55460. This patch adds a `buildEnv` function to `php` that has the following features: * `php.buildEnv { extraConfig = /* ... */; }` to specify custom `php.ini` args for the CLI. * `php.buildEnv { exts = phpPackages: [phpPackages.apcu] }` to create a PHP interpreter for the CLI with the `apcu` extension. (cherry picked from commit 0bf5619)
Motivation for this change
Currently no convenient way to set php.ini system wide while invoking php from the command line.
Example usage:
programs.php.enable = true;
programs.php.phpPackage = pkgs.php71;
programs.php.phpOptions = ''
extension=${pkgs.php71Packages.mailparse}/lib/php/extensions/mailparse.so
'';
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)