Created
March 28, 2017 21:18
-
-
Save 3noch/79255f8c5ec3c287b91b7484265a89a8 to your computer and use it in GitHub Desktop.
PHP with configuration in Nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs ? import <nixpkgs> {} | |
, phpPackage ? pkgs.php | |
, phpPackages ? pkgs.phpPackages | |
, opCache ? false | |
, showErrors ? false | |
, extensions ? [] | |
, zendExtensions ? [] | |
, extraConfig ? "" | |
}: | |
let | |
includePackage = directive: packageName: "${directive} = ${phpPackages.${packageName}}/lib/php/extensions/${packageName}.so"; | |
phpIni = '' | |
${pkgs.lib.optionalString opCache '' | |
; WARNING: Be sure to load opcache *before* xdebug (http://us3.php.net/manual/en/opcache.installation.php). | |
zend_extension = "${phpPackage}/lib/php/extensions/opcache.so" | |
''} | |
${pkgs.lib.concatMapStringsSep "\n" (includePackage "extension") (extensions)} | |
${pkgs.lib.concatMapStringsSep "\n" (includePackage "zend_extension") (zendExtensions)} | |
${pkgs.lib.optionalString showErrors '' | |
error_reporting = E_ALL | |
display_errors = On | |
''} | |
${extraConfig} | |
''; | |
customPhpIniDir = pkgs.writeTextDir "php.ini" phpIni; | |
in pkgs.writeScriptBin "php" '' | |
#!${pkgs.bash}/bin/bash | |
export PHP_INI_SCAN_DIR=$PHP_INI_SCAN_DIR:'${phpPackage}/etc':'${customPhpIniDir}' | |
${phpPackage}/bin/php "$@" | |
'' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage: